Hello all, I have a tricky little problem here and hope someone can help who has experienced the same issue and if not has the know how to help me.
I have this php script and I have incorporated a javascript as well that tells how many members are online and the javascript calls the php script to prevent multiple logons with the same username and password.
My problem is that it works great however once logged in I press the refresh button and it appears to run the javascript telling me “Someone else is already logged in under that username”.
That is what I should get once I log on the second time with the same username and password.
In summary I log on once with a specified username and password however when I depress the refresh button it’s as if I am trying to log on again with the same username and password. The script appears to run twice on refresh.
Hope I explained my situation clear here if not please let me know. I have attached the code I am using and the two different pages and I delete the session on logout but we don’t need that code here since it works great.
main.php
include (“ppl_login.htm”);
if ($online_check > 0){
echo “<b><font face=arial color=red>Someone else is already logged in under that username</font></b>”;
echo
“<script type=”text/javascript”>
setTimeout(“location.href=’
</script>”;
exit();
}
ppl_login.htm
<?
$usernameOL = $username;
$result = mysql_query(“SELECT usernameOL FROM ppl_online WHERE usernameOL =’$usernameOL'”);
$online_check = mysql_num_rows($result);
if ($online_check == 0){
@mysql_query(“INSERT INTO ppl_online (usernameOL, activity, ip_address, refurl, user_agent) VALUES (‘$usernameOL’, now(), ‘{$_SERVER[‘REMOTE_ADDR’]}’, ‘{$_SERVER[‘PHP_SELF’]}’, ‘{$_SERVER[‘HTTP_USER_AGENT’]}’)”);
} else {
if($online_check > 0 ){
@mysql_query(“UPDATE ppl_online SET activity=now() WHERE usernameOL = ‘$usernameOL'”);
}
// 5 Minute time out. 60 * 5 = 300
$maxtime = time() -3600;
$sql = mysql_query(“DELETE FROM ppl_online WHERE UNIX_TIMESTAMP(activity) < ‘$maxtime'”);
mysql_query(“UPDATE ppl_online SET refurl = ‘{$_SERVER[‘PHP_SELF’]}’ where usernameOL =’$usernameOL'”);
}
?>
Regards,
alias_0502