ldap_search filter with memberOf
| From: | Zaitchik, Alan | Date: | Mon, 23 Feb 2009 01:22:55 +0000 |
| Subject: | ldap_search filter with memberOf | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-288661@lists.php.net to get a copy of this message | ||
I am trying to construct a filter for ldap_search that tests the AD memberOf attribute. The latter
has possibly multiple values for a given user, and I want something like (memberOf=*Student*) to get
all and only the students. I realize that the above does not work, that the memberOf attribute has
some internal structure that requires something more complicated, but I cannot seem to get it
working.
What I have done is use a very broad $filter, an $attribs that includes "memberOf"-- and
then loop through the results keeping only the students, thus:
$sr= ldap_search($ldapconn, $dn, $filter, $attribs);
for
($entryid=ldap_first_entry($ldapconn,$sr);$entryid!=false;$entryid=ldap_next_entry($ldapconn,$entryid)){
$this_memberof = implode(ldap_get_values($ldapconn,$entryid,'memberof'));
If (stripos($this_memberof,'student') ) {
// do something, etc.
}
}
But this is wildly inefficient. How can I just create the filter I need for ldap_search?
Thanks!
Alan