Jump to content

[SOLVED] Updating database on browser close.


GB_001

Recommended Posts

The best way to accomplish that is to have a field in your users table like 'last_active'. And then every time the user does something on your site, update that field with the current time. To get 'online' users, just select the ones where last_active is less then 10 minutes old.

it would be easier to do something like this

 

<?php
$id = $_SESSION['id'];
mysql_query("UPDATE users SET last_active=NOW() WHERE id='$id'");

$wq = mysql_query("SELECT username FROM users WHERE last_active > (NOW() - INTERVAL 5 MINUTE)");

while($row = mysql_fetch_array($wq)){
echo $row['username'] . "<br>\n";
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.