开发者

Get SamAccountname from LDAP using PHP

开发者 https://www.devze.com 2023-03-15 18:36 出处:网络
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?

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.


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

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

and do the search.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号