The PHP filter is ldap_search (). How to search for a user

$ _ SERVER ['REMOTE_USER'] returns the name of the user registered by the user in Active Directory. I want to download this information using ldap_search ().

This is what I have now:

$ad = // ldap_connection id
$filter = "(|(sn=$username*)(givenname=$username*))";
$attr = array("displayname", "mail", "mobile", "homephone", "telephonenumber", "streetaddress", "postalcode", "physicaldeliveryofficename", "l");
$dn = // OU, DC etc..

ldap_search($ad,$dn,$filter,$attr);

This works, but I'm not sure if it will work if two users have almost the same names. How can I only find my unique username, so that I always get only one user?

+3
source share
2 answers

sAMAccountName - , Active Directory, (&(objectClass=user)(sAMAccountName=%s)) LDAP ( %s ).

, $username, , , LDAP (. RFC 2254):

ACII < 32, LDAP "*", "(", ")" "\" ( ) , , .

+4

ldap_search() , . , $link - LDAP, ldap_connect() ldap_get_entries ($ link, $result) , :

$result = ldap_search();
if(ldap_count_entries($link, $result) === 1) {
    ...
}

$result = ldap_search();
$entries = ldap_get_entries($link, $result);
if(sizeof($entries) === 1) {
    ...
}
+3

Source: https://habr.com/ru/post/1747503/


All Articles