Php – Can’t bind to LDAP

ldapPHP

I'm trying to develop an application which uses the same login we use in our company to log in our computer, that is, an Active Directory.
So, I'm sure which is my user and my password but it seems every time I try to bind it throws this:

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server

But the ldap_connect success.

So, it must be something related with the username.

I've tried with:

$user='cn=username,o=domainname';

and

$user='domainname\username';

Without success. I've admin access to the domain controller so I could find whatever is needed.

Can someone bring some light to this?

Best Answer

You do not connect when calling ldap_connect. See the PHP manual:

When OpenLDAP 2.x.x is used, ldap_connect() will always return a resource as it does not actually connect but just initializes the connecting parameters. The actual connect happens with the next calls to ldap_* funcs, usually with ldap_bind().

I guess you have some network problems here. One of the following:

  • Your web server cannot resolve the ldap server hostname
  • Your web server may not connect to the ldap server (firewall issue)
  • Your web server cannot find a route to the ldap server (missing routes)
  • You've specified the wrong port