1
votes

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 is 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?

2

2 Answers

3
votes

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 (...)
}
1
votes

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);
    ...
}