views:

27

answers:

2

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_unbind($ldap);
  } else {
   echo "NOT IN GROUP";
   ldap_unbind($ldap);
  }

 } else {
  echo "FAIL BIND";
  ldap_unbind($ldap);
 } 
A: 

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."

geo
I am not trying to Add or Edit a user's attributes, only query what groups he is a memberOf. This is possible as far as I can tell from Google searches - I have been trying to get working code. The code above is from following articles online, but something must be wrong with it
Sam
A: 

Got it to work, my DN was wrong Code is right

Sam