Hey, i am working with the following "number_of_online_users" script, here's the code :
<?php
session_start();
function getusersonline()
{
$count = 0;
$handle = opendir(session_save_path());
if ( $handle == false )
{
return -1;
}
while ( ($file = readdir($handle)) != false )
{
if ( ereg("^sess", $file) )
{
$count++;
}
}
closedir($handle);
return $count;
}
$usercount = getusersonline();
echo "Number Of Online Users : ". $usercount;
?>
the problem is simple, it always increase the number even if the user closes the site, and not decrease it by either the departure of the user from the site or by the expiration of the session... i wanna alter this code to decrease our number of online users when he/she leaves the site, any idea ?
// //
my second question is about the expiration of the sessions, for example, i want from the following script to the session to be expired after 5 minutes, but it is not expiring, why ?
<?php
session_cache_expire(5);
session_start();
if ( !isset($_SESSION["admin"]) || empty($_SESSION["admin"]) )
{
echo "You Are Not Allowed To See This Page<p>| <a href=\"home.php\">Home</a> |</p>";
}
else
{
echo "Welcome " . $_SESSION["admin"] . " To Your Administration Panel";
echo "<br /><br />";
echo "| <a href=\"admin_logout.php\">Logout</a> |";
}
?>
and what about the : session_cache_limiter('private'); ? what is it ?
and the : session.gc_maxlifetime ? what is it ?
Regards