We use an LDAP server to authenticate our users. Because the server is accessed remotely, there’s a rather high plausibility that our webserver will be online, and the LDAP server will be down for maintenance.
Right now, when ldap_bind fails, I assume it is a user authentication issue (wrong username/pass) and I display a message to the user. However, if the connection to the LDAP server is failing (and it’s not necessarily a credentials problem) then I end up with hundreds of users telling me that their password isn’t working when that isn’t the problem.
How can I recover from this? ldap_connect seems to succeed in all cases, as the connection is deferred until ldap_bind is called. The return value from ldap_bind is a simple boolean, and while the warning message displayed by PHP is informative, that doesn’t help my code out too much.
Use
ldap_errno().http://php.net/manual/en/function.ldap-errno.php
List of possible error codes: http://www.php.net/manual/en/function.ldap-errno.php#20665