Page 1 of 1

Members On Script

Posted: Sat Jul 26, 2003 8:43 pm
by daniworldwide
Is there any way to keep track of when a person clicks out of the current page?

Example: If a member clicks a page on my site, it will show up that he is currently on that page, and when he loads a new page, it doesn't show up anymore?

I have something like it for my site currently. Members who are currently logged on. Its a simple time function. If you logged in, in the last hour, you are "online." I'd like it more exact, but I don't quite know how to do it. This is my current function, roughly.

Log.php:

Code: Select all

<?php


$timenow = time();

$sql = ("UPDATE members SET atime='$timenow' WHERE mid='$mid'")
or die ("cannot select updae active time");

$result = mysql_query($sql);

$sql = ("UPDATE members SET logged_on='1' WHERE mid='$mid'")
or die ("cannot select updae active time");

$result = mysql_query($sql);



?>
Logoff.php

Code: Select all

<?php


$timenow = time();


$result = mysql_query("SELECT mid, atime FROM members WHERE logged_on='1'")
or die ("cannot select last logged in time");

while ($row = mysql_fetch_array($result))
{
$mid = $row["mid"];
$atime = $row["atime"];

$timediff = $timenow - $atime;

 if ( $timediff >= 3600) 
{

$sql = mysql_query("UPDATE members SET logged_on='0' where mid='$mid'") or die ('cannot log off membrers');

$sql = mysql_query("UPDATE members SET atime='0' where mid='$mid'") or die ('cannot reset members last active time on the site');

} //end if
} //end while


?>
Thanks!

-Dani

...

Posted: Sat Jul 26, 2003 11:42 pm
by kettle_drum
Umm to make it more accurate you could make it so that users were offline if they havent requested a page in like 5 mins.

Something else you could try is using the javascipt function onUnload to open a new window that would tell the server that the user was leaving the site. But remember that popups are HIGHLY annoying. Maybe you could try this same method but using a frame with 0 width/height.

Posted: Sat Jul 26, 2003 11:48 pm
by daniworldwide
Thats a very good idea, Thanks!