PHP to Query LDAP, check if memberof against a paramater

adznon
adznon used Ask the Experts™
on
I am using PHP to search a LDAP member of list to see if a user is a member of a group "GG-UK-Pink-Stores 2136 StoreManager" and then if they are a member pull out the four digit store number.

It works however it doesnt seem to check for the StoreManager and bring back anything similar.

// *****************************************************
// Searches for the Key of Store Manager within the array.
// *****************************************************
      $keysval = ['StoreManager'];
      foreach($ldapGroups[0]['memberof'] as $k => $v) {
        if ($k === 'count') continue;
        echo $v . "<br>";
        if (preg_match('/.*? (\d\d\d\d) .*/', $v, $match)) {
            $keyval[$match[1]] = true;
        }
        
      }
      $retailOutletNumbers = array_keys($keyval)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
If I understand correctly (based on your earlier questions) you want to be able to extract the 4 digit number from records that have the $keyval string AFTER the 4 digit value?

 foreach($ldapGroups[0]['memberof'] as $k => $v) {
  if ($k == 'count') continue;
  echo $v . "<br>";
  if (preg_match('/.*? (\d\d\d\d) StoreManager.*/', $v, $match)) {
    $keyval[$match[1]] = true;
  }
  
}

Open in new window

Author

Commented:
Perfect, many thanks
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial