Trouble with PHP LDAP code to check memberOf a certain group
I am having trouble with the following code which should check to see if $user is in AlumniDBusers or AlumniDBmanagers groups in AD
The entries[0] array always returns blank
Can anyone see what might be wrong?
Thanks
// Active Directory server
define('LDAP_HOST','dc1.college.school.edu');
// Active Directory DN
define('LDAP_DN','OU=Alumni Relations,OU=Departments,DC=college,DC=school,DC=edu');
// Active Directory user group
define('LDAP_USER_GROUP','AlumniDBusers');
// Active Directory manager group
define('LDAP_MANAGER_GROUP','AlumniDBmanagers');
$ldap = ldap_connect(LDAP_HOST);
echo "LDAP CONNECTED<br />";
if($bind = ldap_bind($ldap, $user, $password)) {
echo "PASS BIND<br />";
$filter = "(samAccountName=" . $user . ")";
$attrs = array("memberOf");
$result = ldap_search($ldap, LDAP_DN, $filter, $attrs);
$entries = ldap_get_entries($ldap, $result);
echo "ENTRY RESULTS: ";
print_r($entries[0]['memberOf']);
echo "<br />";
// see if member is in user or manager group
if (in_array(LDAP_USER_GROUP,$entries[0]['memberOf']) || in_array(LDAP_MANAGER_GROUP,$entries[0]['memberOf']))
{
echo "IN GROUP";
ldap开发者_JAVA技巧_unbind($ldap);
} else {
echo "NOT IN GROUP";
ldap_unbind($ldap);
}
} else {
echo "FAIL BIND";
ldap_unbind($ldap);
}
Got it to work, my DN was wrong Code is right
link text PHP manual
"When adding/editing attributes for a user, keep in mind that the 'memberof' attribute is a special case. The memberOf attribute is not an accessible attribute of the user schema."
精彩评论