benifactor wrote:
i have built a function to tell me how many users are on my site at
any given time... <?
//define function
function bc_who ($who, $location) {
//first we erase any expired entries //entries will expire after 5
mins $whoTime = time(); $whoTime = $whoTime - 300;
mysql_query("Delete FROM bc_who where expire < $whoTime") or
die(mysql_error());
//here we difine the variables needed to preform the check $whoExpire
= time(); $whoIp = "$_SERVER[REMOTE_ADDR]";
//this will be changed as soon as user registration is finished
$whoUser= "Guest"; //do the actual mysql queries
mysql_query("Delete FROM bc_who where '$whoIp' = ip");
mysql_query("Insert INTO bc_who (id, user, ip, location, expire,
status) VALUES (NULL, '$whoUser', '$whoIp', '$location',
'$whoExpire', '$whoStatus')");
}
//end who is function
?>
this fuction works fine, however, i want to know if what i am about
to ask is possible.
the problem i have is, this function assumes that after five minutes
if the user has not refreshed the page, or gone onto another page the
user must be gone. in reality, i have pages users might be on for an
hour or so without refreshing. i want my whos online to as acurate as
possible so is there a way to do this on the fly? like, forgetting
about the expire time and using a server side peice of code to
communicate to the database, when there is no more communication the
entry is deleted? please tell me there is a way, thank you in
advance.
Assuming you actually mean "client side" not "server side" (because
server-side is what you already have), you could do this in a number of
ways with Javascript. You could periodically call the server using
XmlHttpRequest, or you could keep it simple and reload an image which
points at a PHP script. Either way this is not a question for a PHP list
because it relates to client-side code. Google will almost certainly
have several useful sites.
-Stut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php