PHP LDAP Search Root of Active Directory

Using PHP to query Active Directory resulted in a few problems e.g.

Warning: ldap_search() [function.ldap-search]: Search: Can’t contact LDAP server in …

ldap_search(): Search: Operations error
Warning: ldap_search() [function.ldap-search]: Search: Partial results and referral received

The errors only appeared when trying a search from the AD root, the errors disappeared when the search was carried out on an OU.

To solve these problems the following 2 lines are needed between the connection and the bind. The location is important !

ldap_set_option ($ldap_connection, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3);

4 Comments to “PHP LDAP Search Root of Active Directory”

  • Thank you man, you saved me a day of reading ldap documentation, I think!

  • Thanks — this solved my problem immediately.

  • Thank you. A week of debugging code…and these two lines were all i needed.

  • Thank you. I had found and tried the first line, but it was the second line I needed to set me free.

Post comment