开发者

php/ldap - bind fails but errorno doesn't execute

开发者 https://www.devze.com 2022-12-24 14:39 出处:网络
I am trying to connect to ldap with a php web application. If the username/password is correct everything works fine however if the username/password i开发者_如何学Cs incorrect I get the following err

I am trying to connect to ldap with a php web application. If the username/password is correct everything works fine however if the username/password i开发者_如何学Cs incorrect I get the following error:

PHP Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Invalid credentials

for some reason I am not able to look at the errorno or the state of the bind variable afterwards to print the appopriate user friendly error message.

any ideas?


The problem is most likely that ldap_errno takes the ldap connection resource, and as ldap_bind failed you can't use it's result to retrieve the errno.

Also: have you tried suppressing the error via the @ sign?

e.g.:

$ldapconn = ldap_connect("localhost");
@$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

if( $ldapbind )
{
  // Everything went fine
} else {
  // Use the connection resource for ldap_errno
  $errno = ldap_errno( $ldapconn );

  // Check the error number, print an error message (...)
}


You have to check if your ldap connection is ok before trying to bind :

$ldap_conn = ldap_connect($ldap_host,$ldap_port);
if ($ldap_conn) {
    ldap_bind($ldap_conn, $ldap_user_dn, $ldap_pass);
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号