Help with Session and GLOBAL variables...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TwinkiE_HunteR-G
Forum Newbie
Posts: 14
Joined: Tue Sep 17, 2002 8:44 am

Help with Session and GLOBAL variables...

Post by TwinkiE_HunteR-G »

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.

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;
?>
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
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

No, Remember, ASP is a framework, PHP is a language. So basically, in PHP, you create your own method of application variables.

Use a database, and just store the total number of users there.
Post Reply