views:

231

answers:

1

I am using adldap http://adldap.sourceforge.net/

And I am passing the session from page to page, and checking to make sure the username within the session is a member of a certain member group, for this example, it is the STAFF group.

<?php
    ini_set('display_errors',1);
    error_reporting(E_ALL);
    require_once('/web/ee_web/include/adLDAP.php');
    $adldap = new adLDAP();

    session_start();

    $group = "STAFF";

    //$authUser = $adldap->authenticate($username, $password);

    $result=$adldap->user_groups($_SESSION['user_session']);

    foreach($result as $key=>$value) {
        switch($value) {
            case $group:
                print '<h3>'.$group.'</h3>';
                break;

            default:
                print '<h3>Did not find specific value: '.$value.'</h3>';
            }
        if($value == $group) { print 'for loop broke'; break; }
    }
?>

It gives me the error: Warning: Invalid argument supplied for foreach() on line 15, which is this line of code: foreach($result as $key=>$value) {

When I uncomment the code $authUser = $adldap->authenticate($username, $password); and enter in the appropriate username and password, it works fine, but I shouldn't have to, since the session is valid, I just want to see if the username stored within the valid_session is apart of the STAFF group.

Why would it be giving me that problem?

+1  A: 

According to this source file, user_groups() will, return false if the user name was empty (and in some other cases too, check the source). I bet your $_SESSION["user_session"] is empty, and $result is then false. You can't run foreach on a non-array which is why you get the warning.

You will need to find out why your session variable is empty, and/or check whether $result is an array because doing a foreach on it:

if (is_array($result))
 foreach ($result....
Pekka
I printed out the variable and it printed the appropriate username. $_SESSION['user_session']
Brad
$result is not an array, thats a good start to see why it isn't.
Brad
@Brad then it's either this line: `if (!$this->_bind){ return (false); }` or further along the recursive `recursive_groups` function. Make sure you look in your version of the adldap source code, though.
Pekka
I'd have to bind before even thinking of using user_groups()? I imagine I should use ldap_search() for the username that is stored w/i the valid session, then if it returns a the group I am looking for, then return true.
Brad
@Brad I can't help you there, sorry, I don't know the software....
Pekka
What I need to do is look to see if the user is a member of a specific group, if so, then they can access that page, if not, they can't see it.
Brad