The code to show if a user is online or offline for my website isnt working at all.
It will show someone's online for about 15 or 10 minutes , then they can still be logged in , but if will show them as offline.
Even when im logged in , my session will still be active , but it shows me logged off after so long.
This is the PHP code responsible for taking data from the sessions table and figuring out if the user is offline or online ...
Is their anohter way to write this so that it works?
$gu_sql = "select data from $tb_sessions";
$gu_query = mysql_query($gu_sql) or die(mysql_error());
$total_user_sessions = mysql_num_rows($gu_query);
if($total_user_sessions)
{
$username_array = array();
$userid_array = array();
while($gu_array = mysql_fetch_array($gu_query))
{
if(strlen(trim($gu_array["data"])))
{
$strings = split(";", $gu_array["data"]);
for($x = 0; $x < sizeof($strings); $x++)
{
if(strlen($strings[$x]))
{
if((eregi("^username", $strings[$x])) ||(eregi("^}username", $strings[$x])))
{
$parts = split(":", $strings[$x]);
$username_array[] = eregi_replace("\"", "", $parts[2]);
}
}
}
}
}
$user_status="Offline";
if(sizeof($username_array))
{
$un = array_unique($username_array);
for($z = 0; $z < sizeof($un); $z++)
{
if($un[$z] == $array[user_name])
{
$user_status="Online";
break;
}
}
}
Im very confused why this isnt working , any help would be great , thanks.