Authentication using Zimbra LDAP and PHP

Zimbra Version

[zimbra@mailbox ~]$ zmcontrol -v
Release 8.8.15_GA_3829.RHEL6_64_20190718141144 RHEL6_64 FOSS edition, Patch 8.8.15_P1.

PHP Version

[gia@WEB01 ~]# php -v
PHP 7.3.26 (cli) (built: Jan 5 2021 10:36:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.26, Copyright (c) 1998-2018 Zend Technologies

PHP Code

<?php
$ldap['user'] = 'emailuser';
$ldap['pass'] = 'emailuserpassword';
$ldap['host'] = 'zimbra.mailserver.com';
$ldap['port'] = 389;
$ldap['dn']   = 'uid='.$ldap['user'].',ou=people,dc=mailserver,dc=com';
$ldap['conn'] = ldap_connect( $ldap['host'], $ldap['port'] );
ldap_set_option($ldap['conn'], LDAP_OPT_PROTOCOL_VERSION, 3);
$ldap['bind'] = ldap_bind( $ldap['conn'], $ldap['dn'], $ldap['pass'] );
if ($ldap['bind']) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed...";
}
?>

Test

[gia@WEB01 ~]# php zimbra.php
LDAP bind successful...
[gia@WEB01 ~]#

Source

https://forums.zimbra.org/viewtopic.php?t=1516
https://wiki.zimbra.com/wiki/ShanxT-LDAP-CheatSheet

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.