I am using adldap http://adldap.sourceforge.net/开发者_如何学C
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?
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....
精彩评论