ShopMAster Posted March 5, 2007 Share Posted March 5, 2007 Hey guys, this is probably very simple just need some help. I have a membership site that I created and as one of the last things I wanted to do was to set when members are online or not. So I know there was probably an easier method but what I did was add a online field to the member table. When a sucessful login is made they go to a loggedin.php page and on that page I have the following code: $query = "UPDATE mwcplayers SET online=1 WHERE id= '".$_SESSION['id']."'"; This works great the users online status is set to 1. My problem is when they log out and getting that online status set to 0 again: here is my logout page logout.php: <?php session_start(); session_unset(); $mesaj = ''; include 'index.php'; exit(0); ?> I have no clue as to where to put the sql statement to set their online status to 0. Please help. Thanks. Shopmaster Link to comment https://forums.phpfreaks.com/topic/41323-log-out-and-set-online-counter-to-0/ Share on other sites More sharing options...
paul2463 Posted March 5, 2007 Share Posted March 5, 2007 <?php session_start(); $query = "UPDATE mwcplayers SET online=0 WHERE id= '".$_SESSION['id']."'"; mysql_query($query) or die ("cannot amend table" . mysql_error()); session_unset(); $mesaj = ''; include 'index.php'; exit(0); ?> Link to comment https://forums.phpfreaks.com/topic/41323-log-out-and-set-online-counter-to-0/#findComment-200232 Share on other sites More sharing options...
ShopMAster Posted March 5, 2007 Author Share Posted March 5, 2007 Thanks, worked liked a charm after I add the DB connection. Mucho Gracias!! Link to comment https://forums.phpfreaks.com/topic/41323-log-out-and-set-online-counter-to-0/#findComment-200237 Share on other sites More sharing options...
ShopMAster Posted March 6, 2007 Author Share Posted March 6, 2007 Quick question, what should I do about people who do not log out but their session has ended, it will still be set to 1 thus showing them online. Link to comment https://forums.phpfreaks.com/topic/41323-log-out-and-set-online-counter-to-0/#findComment-200705 Share on other sites More sharing options...
trq Posted March 6, 2007 Share Posted March 6, 2007 If your mwcplayers table also has a timestamp field the easiest option is to run a cron job to test and see who has timestamps older then say 10 minutes and delete them. Of course this also meens you'll need to update the timestamp field on each request. Link to comment https://forums.phpfreaks.com/topic/41323-log-out-and-set-online-counter-to-0/#findComment-200707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.