KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is the best way to run a search on the current user to retrieve all attributes, including associated groups in Active Directory using LDAP / PHP? For attributes, mainly just first name, last name, and display name. For associated groups, just the groups the user is a member of, such as the memberOf function. I've tried a few options, but can't seem to get the right filter / search combination and most examples cover retrieving lists of users where there's a known group. I've tried running this after a successful bind: $attributes = array("displayname"); $filter = "(&(sAMAccountName=$username))"; $result = ldap_search($ds, $ldapconfig['basedn'], $filter, $attributes); $entries = ldap_get_entries($ds, $result); if($entries["count"] > 0){ echo "displayName: ".$entries[0]['displayname'][0]."<br/>"; } else { echo("msg:'".ldap_error($ds)."'</br>"); } Which returns the following error: "No such object". UPDATE: This is the latest block I've tried and am able to get results when I print_r the $info variable, however the for clause is still erring out somewhere. I changed the basedn to just the dc attributes: $filter="($SearchField=$SearchFor)"; $sr=ldap_search($ds, $basedn, $filter, $LDAPFieldsToFind); $info = ldap_get_entries($ds, $sr); if($info["count"] > 0) { for ($x=0; $x<$info["count"]; $x++) { $sam=$info[$x]['samaccountname'][0]; $giv=$info[$x]['givenname'][0]; $tel=$info[$x]['telephonenumber'][0]; $email=$info[$x]['mail'][0]; $nam=$info[$x]['cn'][0]; $dir=$info[$x]['homedirectory'][0]; $dir=strtolower($dir); $pos=strpos($dir,"home"); $pos=$pos+5; if (stristr($sam, $SearchFor) && (strlen($dir) > 8)) { print "\nActive Directory says that:\n"; print "CN is: ".$nam." \n"; print "SA
Tags (comma-separated)
Save Edits
Cancel