1
votes

Ldap Authentication works. I just want to get the samaccountname from Ldap using php. I can get the users email, and OU and display name, but is there a way to get the SamAccountName?

I'm using this:

if (@!$loginldap = ldap_bind($ds, "$username@$ldap_domain", $password)) { 
  if ($loginldap) { // if binding to ldap works
   $attributes = array("displayname", "mail");
   $filter = "(&(objectCategory=person)(sAMAccountName=$username))";
   $result = ldap_search($ds, $ldap_dn, $filter, $attributes);
   $entries = ldap_get_entries($ds, $result);
  }
}

and the $entries array contains all the stuff I need except for SamAccountName.

Thanks.

1

1 Answers

0
votes

You have to explicitly request the samaccountname. Add it to the attributeList

$attributes = array("displayname", "mail", "samaccountname"); 

and do the search.