Hello....
I am running into an issue with ldap. First, I've never used ldap before and I am trying to do a search from an example in the manual. The thing I don't really understand is drilling into the directory structure.
Our ad server(windows) is setup like:
-> ouradserver.com
-> our administrators
-> users
I can connect fine but when I try to do a search I am getting an error.
Here is the code I am using:
echo "<h3>LDAP query test</h3>";
echo "Connecting ...";
$ds=ldap_connect("LDAP://XXXDC1"); // must be a valid LDAP server!
echo "connect result is " . $ds . "<br />";
if ($ds) {
echo "Binding ...";
$r=ldap_bind($ds);
echo "Bind result is " . $r . "<br />";
echo "Searching for (sn=S*) ...";
// Search surname entry
//$sr=ldap_search($ds, "sn=S*");
$person = "s";
$dn = "o=Company, c=US";
$filter="(|(sn=$person*)(givenname=$person*))";
$justthese = array("ou", "sn", "givenname", "mail");
$sr=ldap_search($ds, $dn, $filter, $justthese);
echo "Search result is " . $sr . "<br />";
echo "Number of entries returned is " . ldap_count_entries($ds, $sr) . "<br />";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for " . $info["count"] . " items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) {
echo "dn is: " . $info[$i]["dn"] . "<br />";
echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />";
echo "first email entry is: " . $info[$i]["mail"][0] . "<br /><hr />";
}
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
ldap_close($ds);
I feel like I am missing something in the DN.. maybe OU=SubDir?? Here are the errors I am getting:
- Warning: ldap_search() [function.ldap-search]: Search: Operations error in
- Warning: ldap_count_entries() expects parameter 2 to be resource, boolean given
- Warning: ldap_get_entries() expects parameter 2 to be resource, boolean given
Are those errors all caused b/c of the first error on the ldap_search()?
I appreciate any insight.