When they leave the site, it deletes that IP address in a DB - thus seeing at any one moment how many "people" are on the site.
I know how to log the IP when they visit (easy of course), but I don't know how to delete it when they close their browser or leave the site entirely.
We had an issue once when I wanted to sign them out when they left the site, but we had an issue where it ran the script when they just left the page for another page on the site.
So it's the latter bit I am stuck on. If possible - this would be amazing as the site gets very high traffic and be very cool!!
Trying to use this:
Code: Select all
$result = mysql_query ("SELECT ipaddress FROM usersonsite WHERE ipaddress = '$iplog'");
$num_result = mysql_num_rows($result);
if ($num_result == NULL)
{
mysql_query("INSERT INTO usersonsite(ipaddress) VALUES ('$iplog')");
}
?>
<body onunload="bye()">
<script>
function bye()
{
var php_value = 2;
var address = "loggedusers?php_value="+php_value
document.getElementById('im1').src = address
}
</script>then if the body us unloaded, it runs the bye() script which triggers loggedusers.php. That script deletes the IP address.
Trouble is - it isn't working!! The INSERT works, but nothing I do will make the loggedusers.php run.
I've tried onunload, onbeforeunload etc. Is there a foolproof method? I understand this will be a JAVASCRIPT thing, so perhaps it should be in that section instead.
I'm just thinking there must be a way, either in PHP or with PHP and Javascript.
It's just so I can show on screen how many users are onscreen - preferably by showing how many IPs are logged in a DB at any one time.