简体   繁体   中英

Ldap how to get memberof

How to get memberof the user filter? Not all users have memberof.

$ds = `000.000.000.000`;
$ldaprdn  = `CN=Users,dc=xxx,dc=xx,dc=xx,dc=xx`;    
$user = `CN=UserSystem,`;
$ldappass = `pass`;

// connect to ldap server
$ldapconn = ldap_connect("000.000.000.000") or die(`Could not connect to LDAP server.`);

if ($ldapconn) {
    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $user.``.$ldaprdn, $ldappass);
    // verify binding
    if ($ldapbind) {        
        ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
        ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);

        $sr=ldap_search($ldapconn, $ldaprdn, `(&(objectClass=user)(sAMAccountName=testuser))`);
        $info = ldap_get_entries($ldapconn, $sr);

        $ii=0;
         for ($i=0; $ii`;
              if ($data == `memberof`) {
            $membrog = explode(`,`, $info[$i][$data][0]);
            $membrode = explode(`=`, $membrog[0]);
            echo $membrode[1].`
`; } } ldap_close($ldapconn); } else { echo `Connection to LDAP Failed`; } }

If you are looking at groups a user is a memberOF, from LDAP, Because of group nesting, you may need to use a filter which utilizes MATCHING_RULE_IN_CHAIN, like shown on this page.

-jim

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM