I'm new to LDAP and I'm looking to pull information from our AD server. I installed the DLLs, enabled LDAP in php.ini and restarted our NT webserver running IIS. I can connect and bind perfectly, but receive the following error when I query:
Warning: ldap_search(): Search: Operations error in ...
Here's what my code looks like:
<?
// Connect to the directory server.
$ad = ldap_connect("ldap://server.domain.local")
or die("Couldn't connect to AD!");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
// Bind to the directory server.
$bd = ldap_bind($ad,"username@domain.local","password") or
die("Couldn't bind to AD!");
echo "SUCCESS!";
// Carry out directory server-specific tasks.
$dn = "DN=domain,DN=local";
$filter = "(cn=*)";
$result = ldap_search($ad, $dn, $filter);
$entries = ldap_get_entries($ad, $result);
for ($i=0; $i<$entries["count"]; $i++)
{
echo $entries[$i]["displayname"]
[0]."(".$entries[$i]["l"][0].")<br />";
}
// Close the connection
ldap_unbind($ad);
?>
Any assistance would be greatly appreciated. Getting this work will be awesome!