who is online?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux