Help with Session and GLOBAL variables...
Posted: Thu Sep 19, 2002 4:20 pm
Ok, so Im working on my own WWWBoard, using PHP of course.
Now, I want to be able to show the users whos on, or even just how many people are on.
I wrote this origonally in ASP, and ASP has global.asa, so whenever a new session started i just increased a global variable and there ya go.
Now is there any sort of variable that will cross sessions?
I tried $GLOBAL['users'], but this is what happens.
I have that set up at the beginning of index.php.
Now, it works the very first time i try it, then it tells me...
Warning: Variable passed to reset() is not an array or object in c;\inetpub\wwwroot\WWWBoardPHP\Index.php on line 49
Warning: Invalid argument supplied for foreach() in c;\inetpub\wwwroot\WWWBoardPHP\Index.php on line 50
So, apparently its not getting to where its setting the GLOBALS['users'] after the first, because the session['counted'] has been set to true.
So is there anything else that I should try? Is there some sort of cross-session, application level variable I could use? Id appreciate any information.
Thanks alot
-TwinkiE
Now, I want to be able to show the users whos on, or even just how many people are on.
I wrote this origonally in ASP, and ASP has global.asa, so whenever a new session started i just increased a global variable and there ya go.
Now is there any sort of variable that will cross sessions?
I tried $GLOBAL['users'], but this is what happens.
Code: Select all
<?php
if (!isset($_SESSIONї'counted']) || !$_SESSIONї'counted'])
{
$users = array($GLOBALSї'users']);
$usersїcount($users) + 1] = $_SESSIONї'UserName'];
$_SESSIONї'counted'] = True;
$GLOBALSї'users'] = $users;
}
...
reset($GLOBALSї'users']);
foreach ($GLOBALSї'users'] as $us)
echo $us;
?>Now, it works the very first time i try it, then it tells me...
Warning: Variable passed to reset() is not an array or object in c;\inetpub\wwwroot\WWWBoardPHP\Index.php on line 49
Warning: Invalid argument supplied for foreach() in c;\inetpub\wwwroot\WWWBoardPHP\Index.php on line 50
So, apparently its not getting to where its setting the GLOBALS['users'] after the first, because the session['counted'] has been set to true.
So is there anything else that I should try? Is there some sort of cross-session, application level variable I could use? Id appreciate any information.
Thanks alot
-TwinkiE