need help with LDAP and LDAP_SEARCH

Hi, new to the forums, not new to PHP tho (although I’m not an OOP person).

I’m having trouble figuring out how to query AD to get all the groups that a user manages. I’m presuming the actually LDAP query would be something like (managedBy=$usersDN) like:

[php]$results = ldap_search($ldap, $adbase, “(managedBy=$dn)”);[/php]

However, I’m new to the ldap fuctions in PHP and it’s not really making sense to me. Any help would be appreciated (especially how can I get the groups in to an array so I can print that array out).

Found the answer by adapting someone else’s example:

[php]
if($bind) {
$filter = “(managedBy=$dn)”;
$results = ldap_search($ldap, $adtree, $filter); // ldap_search always returns the DN
$entries = ldap_get_entries($ldap, $results);
$groupsNbr = $entries[‘count’];

		for($b = 0; $b < $entries['count']; $b++) {
			$groupsArr[] = $entries[$b]["dn"];
			}
		}

if($groupsNbr > 0) {
	$form = "<select name='group'>\n";
	foreach($groupsArr as $group) {
		$shortName = extract_unit($group, "CN=", ",OU=");
		$form .= "\t<option value='$group'>$shortName</option>\n";
		}
	$form .= "</select>\n";
	}
else {
	print "You do not manage any groups.";
	}

[/php]

extract_unit is a custom function to “extract” text beween snippits of text–here getting the group name from its distinguishedname.

Meant to follow up. but completely forgot about it with the current workload. PHP is a pain with most LDAP systems.

Sponsor our Newsletter | Privacy Policy | Terms of Service