Mmkay.
You would run against your standard sessions that you would use on a page, for example:
PHP Code:
<?php
session_start();
$_SESSION['lastActivity'] = time();
...
?>
Now, add to it a location (or do it via .ini directly or using an .htaccess file if you have it available), relative to the calling script:
PHP Code:
<?php
ini_set('session.save_path', '/my/path/to/session/storage');
session_start();
...
Now for the fun part. You got to count those sessions:
PHP Code:
<?php
$i = 0;
foreach (glob('/path/to/session/storage/*') AS $sessions)
{
$i++;
}
Voila, simulated counter. This doesn't even keep track of the record time, for that you will need to unserialize the packed data in the session, read the 'lastActivity' hash value, determine if its still online or not, and increment the counter.
Decided to edit this part in to give you an example for how to check to see if its a current session. Not sure if this will actually work how I expect it to, but will give it a shot:
PHP Code:
$i = 0;
foreach (glob('/path/to/session/storage/*') AS $sessions)
{
$sess = unserialize($sessions);
if (is_array($sess) && ($time = array_key_exists('lastActivity', $sess)))
{
if ($time > time() - TIMEOUTCONST)
{
// Still considered online
$i++;
}
}
}
As you can see, this isn't overly pleasant, and I don't want to throw a script together for this purpose >.<.
DB's are a lot easier to deal with (but harder to put together until you get the hang of it). In case you are wondering, I use database sessions exclusively now, haven't used the predefined sessions in years (except to test on them and keep as 'up to date' as I can with them). To count off a DB driven session:
PHP Code:
$qryStr = "SELECT count(*) FROM {SESSIONTABLE} WHERE `lastActivity` > time() - 3600";
$numOnline = $sqlObj->query($qryStr);
All done on that - obviously this is using a custom sql object and query itself won't do, but a simple fetch is all that is required on top of it. The 3600 is mearly a constant number to subtract, think of it as a 'timeout', anyone with no activity after 3600 seconds is considered to be disconnected and not included in the help.
Forum software (like this site) use Database driven session management, thats why the counts are so easy to preform.
Hope this helps you out, and I'm pretty sure I mentioned it already - just search google (or maybe even here not sure if someone has posted one) for a 'database session management in PHP' script or tutorial. There are a lot out there.
Good luck