can you help please - URGENT

Discussion in 'PHP' started by oo7ml, Sep 4, 2008.

  1. #1
    Hi, my site uses LDAP to verify users when they login (this is not an LDAP question :))

    the code below works fine:

              $lrSearch = @ldap_search($lConnect, 'OU=Systems,DC=mydomainname,DC=com', LDAP_USERNAME_FIELD."=".$_SESSION['user'].LDAP_USERNAME_END);
              $nMatchingEntries = @ldap_count_entries($lConnect, $lrSearch);
              if($nMatchingEntries != 1) {
                $this->sLoginFailure = 'Ooops... Invalid username supplied';
                return false;
              }
    PHP:
    however now i need to change the code above as i have more than one group of users. The code above 'OU=Systems,DC=mydomainname,DC=com' is fine if there is only 1 group but now i have 4 groups of users so it must now allow any of these groups below:

    - OU=Systems,DC=mydomainname,DC=com
    - CN=Users,DC=mydomainname,DC=com
    - OU=Business,DC=mydomainname,DC=com
    - OU=Marketing,DC=mydomainname,DC=com

    Can anyone help me create this as quickly, i'm sure there is afew ways to do this. Do i need to use an OR statement or what is required

    thanks in advance
     
    oo7ml, Sep 4, 2008 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $groups = array('OU=Systems,DC=mydomainname,DC=com',
                    'CN=Users,DC=mydomainname,DC=com', 
                    'OU=Business,DC=mydomainname,DC=com',
                    'OU=Marketing,DC=mydomainname,DC=com'
                    );
    
    
    $count = count($groups);
    for ($i = 0; $i < $count; $i++)
    {
        $lrSearch = @ldap_search($lConnect, $groups[$i], LDAP_USERNAME_FIELD . "=" . $_SESSION['user'] .
            LDAP_USERNAME_END);
        $nMatchingEntries = @ldap_count_entries($lConnect, $lrSearch);
        if ($nMatchingEntries == 1)
        {
            break;
        }
    }
    if ($nMatchingEntries != 1)
    {
        $this->sLoginFailure = 'Ooops... Invalid username supplied';
        return false;
    }
    PHP:
    Untested, but it should work
     
    JAY6390, Sep 4, 2008 IP
  3. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Thanks, works perfect
     
    oo7ml, Sep 5, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    awesome :)
     
    JAY6390, Sep 5, 2008 IP