php LDAP search
Posted: Mon Oct 20, 2008 11:44 am
have a question about ldap_search function. Should be easy, but couldn't figure out.
here is what I want:
After first ldap_search in the company's Active Directory, I can retrieve employee's manager information, it is shown in distingushedname format, like this: CN=Kathy William,OU=MIS,OU=MIS,OU=MGM,DC=MGM,DC=com
What I really like is to display the manager's full name - displayName, so I need to run a ldap_search again baed on the manager's distinguishedname, but seems like I can not retrieve any information, the error msg always displayed:"Error: Only one entrie should be returned". Is the $filter syntax wrong???
here is my simple code:
here is what I want:
After first ldap_search in the company's Active Directory, I can retrieve employee's manager information, it is shown in distingushedname format, like this: CN=Kathy William,OU=MIS,OU=MIS,OU=MGM,DC=MGM,DC=com
What I really like is to display the manager's full name - displayName, so I need to run a ldap_search again baed on the manager's distinguishedname, but seems like I can not retrieve any information, the error msg always displayed:"Error: Only one entrie should be returned". Is the $filter syntax wrong???
here is my simple code:
Code: Select all
$base_dn = "ou=MGM,dc=MGM,dc=com";
$filter = "DN='CN=Kathy William,OU=MIS,OU=MIS,OU=MGM,DC=MGM,DC=com'";
$justthese = array("displayname");
$result = ldap_search($ldapconn, $base_dn, $filter, $justthese);
$entries = ldap_get_entries($ldapconn, $result);
$numEntries = $entries["count"];
if ($numEntries != 1)
echo "Error: Only one entrie should be returned\n<br /><br />";
else
{
echo "Display Name: " . $entries[0]['displayname'][0] . "\n<br />";
}