How to check if a user is part of a group using the php_ldap module?
I am completely new to ldap and therefore a bit confused ...
With googling, I came up with this so far:
$ds=ldap_connect($ldapHost, $ldapPort); if ($ds) { $r=ldap_bind($ds, $ldapRdn, $ldapPassword); $filter = "(sAMAccountName=" . $uid . ")"; $attr = array("memberof"); $result = ldap_search($ds, $ldapDN, $filter, $attr) or exit("Unable to search LDAP server");
I am not sure if this is correct since it was taken in a form specific to AD. The problem seems to be equal to $ ldapDN. Is this what I'm looking for right? My definition of groups:
cn=User,ou=Profiles,ou=App_DEV,ou=ApplicationRights,O=MyCompany.COM
How can I do this check?
EDIT:
Here is my solution using the โAccepted Answerโ and trial and error. โI think the answer is highly dependent on your particular system.
//This is the User group DN $ldapDN = "cn=User,ou=Profiles,ou=App_DEV,ou=ApplicationRights,O=MyCompany.COM"; $filter = "(uniqueMember=uid=" . $uid . ",ou=Users,O=MYCOMPANY.COM)"; $attr = array('uniqueMember'); $result = ldap_search($ldapConnection, $ldapDN, $filter, $attr): $entries = ldap_get_entries($ldapConnection, $result); ldap_unbind($ldapConnection); return intval($entries["count"]) > 0;
beginner_
source share