GB_001 Posted February 1, 2008 Share Posted February 1, 2008 How would I be able to update database when the browser closes? -Thankyou, GB. Link to comment https://forums.phpfreaks.com/topic/88841-solved-updating-database-on-browser-close/ Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 There really is no reliable way to do this. You could use the onunload event to execute some AJAX which will let your server know. But again, it's not reliable. What are you trying to accomplish with this? Link to comment https://forums.phpfreaks.com/topic/88841-solved-updating-database-on-browser-close/#findComment-455034 Share on other sites More sharing options...
GB_001 Posted February 1, 2008 Author Share Posted February 1, 2008 I trying to accomplish whether a user can check a list of users that our online. Link to comment https://forums.phpfreaks.com/topic/88841-solved-updating-database-on-browser-close/#findComment-455036 Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 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. Link to comment https://forums.phpfreaks.com/topic/88841-solved-updating-database-on-browser-close/#findComment-455043 Share on other sites More sharing options...
Northern Flame Posted February 1, 2008 Share Posted February 1, 2008 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/88841-solved-updating-database-on-browser-close/#findComment-455044 Share on other sites More sharing options...
GB_001 Posted February 1, 2008 Author Share Posted February 1, 2008 Thankyou, so I just create a timestamp? Do I make it current time? Link to comment https://forums.phpfreaks.com/topic/88841-solved-updating-database-on-browser-close/#findComment-455050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.