Invalid argument supplied for foreach() using adldap
Posted
by Brad
on Stack Overflow
See other posts from Stack Overflow
or by Brad
Published on 2010-03-19T13:18:46Z
Indexed on
2010/03/19
13:21 UTC
Read the original article
Hit count: 403
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?
© Stack Overflow or respective owner