ldap_bind gives warning and not returning false with invalid credentails

Hi Guys,

I am working on LDAP Authentication. The authentication works fine with valid user and password. But it gives me the warning with invalid username and password. The code is


if(@ldap_bind($ds,$user,$pass)) {
 echo "Login successful";
} else {
 echo "Invalid login";
}

The warning I am getting is

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Invalid credentials in C:\wamp\www\ est\ldap_login1.php on line 23

‘@’ removes the warning. I used the ‘@’ before ldap_bind() but still I am getting the warning.

Please help me.

Thanks,

You could, although I think it’s considered bad practice, turn off error reporting globally prior to calling the function then reinstating previous settings.

I would say however, it’s no different to using ‘@’.

The most typical error here is that $user is not the username, but the dn. Example: $user = ‘uid=guest,dc=company,dc=com’;

You need to find out the dn to the user you are trying to bind as.

I used the ‘@’ before ldap_bind() but still I am getting the warning

Seems to be a php bug.

You could try to define an own error_handler:

function errorhandler($code,$message,$file,$line,&$trace) {
   echo $code.'<br />';
   echo error_reporting();
}
set_error_handler('errorhandler');

What´s the result? Always 2 or 32? Is it really always a ‘warning’ (with and without @)?

turn off error reporting

Turning off is no good idea. But you can change the error-reporting-level when everything has been tested. So: it seems to be a bug, but it doesn´t matter.

EDIT:
Or do you already use an own error-handler? Do you ALWAYS output the error-message? If you use @, error_reporting() is 0. Then you shouldn´t echo any error-information.