List groups from user using ldap

I am really new to LDAP and just got the connection between my php server and ad server. I successfully passed user authentication. Now I want to list all the groups in which users will see whether he is an administrator or not (or can there be another way?).

I still have this:

    $ldap = ldap_connect("192.168.1.108");
    if ($ldap && $bind = @ldap_bind($ldap, $name."@foobar.com", $pw)) {
        // ldap_search and ldap_get_entries here i guess, but how?
    }

I tried with ldap_search while reading the manual on php.net, but I could not get it to work at all. Can someone show me how to make it work?

+3
source share
2 answers

I worked with this post: http://www.php.net/manual/en/ref.ldap.php#99347 Anyway, thanks to Aaron.

+4

ldap_get_entries. , , . member - , $data, . , .

// Users
$query = ldap_search($ldap, "cn=Users, dc=test, dc=local", "cn=*");
// Read all results from search
$data = ldap_get_entries($ldap, $query);

// Loop over 
for ($i=0; $i < $data['count']; $i++) {
    print_r($data[$i]['member']);
    echo "\n\n";    
}
+4

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


All Articles