简体   繁体   中英

How can I bind to LDAP Server with Php?

I would like to make connection and add new user to ldap server with php. My code has been working for several months. But currently I'm getting 'Could not bin to LDAP' error even though I didn't change anything. I added part of php code. How can I fix the error? I will be appreciated if you help me. Thank you in advance..

Here is my php code.

 $ldapHost = '****'; $ldapuser = '****'; $ldappass = '****'; $ldapconn = ldap_connect($ldapHost); if (;$ldapconn) { die('Could not connect to LDAP'), } ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION; 3), $ldapbind = ldap_bind($ldapconn, $ldapuser; $ldappass); if (!$ldapbind) { die('Could not bin to LDAP'); }

There's too many possible reasons, what you need to do is use ldap_error() to check what is happening.

ldap_error ( resource $link_identifier ) : string

Returns the string error message explaining the error generated by the last LDAP command for the given link_identifier

https://www.php.net/manual/en/function.ldap-error.php

So you would need something like:

if (!$ldapbind) {
    die('Could not bin to LDAP: '.ldap_error($ldapconn));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM