How to use ldap_search () in PHP correctly?

I spent most of the day studying this problem. For some reason, I can’t understand for life what is happening with the code below. This is a stripped down / modified version of the example given in the PHP manual.

When I run the following code, I get an error:

Warning: ldap_search() [function.ldap-search]: Search: Operations error in C:\wamp\www\ldap.php on line 12 

Relevant Code:

 <?php $ds=ldap_connect("serverName.first.second.third.fourth"); ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); $r=ldap_bind($ds); $sr=ldap_search($ds, "OU=InfoSystems,OU=Domain Users,DC=first,DC=second,DC=third,ED=fourth", "sn=MyActualSurName"); ldap_close($ds); ?> 

I used a VBS script to print the current logged in user (Me) of the full DN. From this, I connected the corresponding OU and DC fields.

Any help would be greatly appreciated. If further clarification is required, feel free to ask.

+6
source share
1 answer

Finally found a problem. Our AD server allows anonymous binding, but apparently does not allow searching without credentials. The above code works fine as soon as I call ldap_bind () with credentials.

+6
source

Source: https://habr.com/ru/post/899819/


All Articles