jackpf Posted February 20, 2009 Share Posted February 20, 2009 Hi all, To determine who is online on my site, I have a "status" column in my users table, which is updated when users log on/off. However, if people simply close the window/browser, then my site thinks they're still online. I was just wondering if there's a better way to go about this. Thanks, Jack. Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted February 20, 2009 Share Posted February 20, 2009 Hi all, To determine who is online on my site, I have a "status" column in my users table, which is updated when users log on/off. However, if people simply close the window/browser, then my site thinks they're still online. I was just wondering if there's a better way to go about this. Thanks, Jack. Although I've never done this, I can only offer a generalization. When users just close their browsers, the server/website will still think the user is online. There is no way to log off the user when they close the browser. So the only thing you can fall back on is sessions. Since sessions live on the server for 20 minutes (I think that's the default) You'd have to check if there has been any activity for that user during that time period. And if they have not made any post or logged onto any forum, you can then probably set their account as offline.. As for the sessions, you can change that too if you don't like the default... Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 20, 2009 Share Posted February 20, 2009 The way I handle it is assume they are online 10-15+ minutes after each page change. Then, if they don't visit a page, they're assumed offline until they return to the site. Edit: Similar to what the poster above described, just not using sessions. I guess you could get fancy with ajax pings, but that could be overkill. Quote Link to comment Share on other sites More sharing options...
Philip Posted February 21, 2009 Share Posted February 21, 2009 Hi all, To determine who is online on my site, I have a "status" column in my users table, which is updated when users log on/off. However, if people simply close the window/browser, then my site thinks they're still online. I was just wondering if there's a better way to go about this. Thanks, Jack. Although I've never done this, I can only offer a generalization. When users just close their browsers, the server/website will still think the user is online. There is no way to log off the user when they close the browser. So the only thing you can fall back on is sessions. Since sessions live on the server for 20 minutes (I think that's the default) You'd have to check if there has been any activity for that user during that time period. And if they have not made any post or logged onto any forum, you can then probably set their account as offline.. As for the sessions, you can change that too if you don't like the default... Sessions default is 2 hours i believe. Best way to do this (as listed above), and how most forums do this... Every time they visit a page, it updates their last timestamp (and location sometimes). Then when listing, whoever's timestamp is greater than now - X minutes, display. Quote Link to comment Share on other sites More sharing options...
jackpf Posted February 21, 2009 Author Share Posted February 21, 2009 Thanks for the response. Yeah...sessions...I did a quick google on how to get session data, so I could see if the sessions still exist, but couldn't really find a straight answer. Is this even possible? I think the second approach sounds like a good idea. I could make a function which checks if they're online, something like this- mysql_connect....etc $status = $fetch['status']; //status being the unix stamp of the last time they visited a page if($status + 1200 <= time()) { $online = 'false'; } else { online = 'true'; } I think I'll go with that, unles anyone has any more suggestion? Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted February 21, 2009 Share Posted February 21, 2009 Thanks for the response. Yeah...sessions...I did a quick google on how to get session data, so I could see if the sessions still exist, but couldn't really find a straight answer. Is this even possible? I think the second approach sounds like a good idea. I could make a function which checks if they're online, something like this- mysql_connect....etc $status = $fetch['status']; //status being the unix stamp of the last time they visited a page if($status + 1200 <= time()) { $online = 'false'; } else { online = 'true'; } I think I'll go with that, unles anyone has any more suggestion? yeah that seems the jist of it...... Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 21, 2009 Share Posted February 21, 2009 Actually default session time depends on the server configuration, and when you close the browser, because I've been able to stay logged in on my clients construction site, when I don't have anything set, but WAMP is defaulted to 1/2 hour. Quote Link to comment Share on other sites More sharing options...
jackpf Posted February 21, 2009 Author Share Posted February 21, 2009 I have no idea, but I'll try the mysql method tbh Quote Link to comment Share on other sites More sharing options...
angelcool Posted February 21, 2009 Share Posted February 21, 2009 Best way to do this (as listed above), and how most forums do this... Every time they visit a page, it updates their last timestamp (and location sometimes). Then when listing, whoever's timestamp is greater than now - X minutes, display. I think this is really the way to go for this, no need for sessions. Although not 100% accurate, extremely close (I'll say 90-99% ) Quote Link to comment Share on other sites More sharing options...
jackpf Posted February 21, 2009 Author Share Posted February 21, 2009 Yeah, it's quite a good way of going about it really. So simple I never though of it Quote Link to comment Share on other sites More sharing options...
npsari Posted February 22, 2009 Share Posted February 22, 2009 I would go for the simple way... Just give a member 10minutes after a page load If the time was not updated, another page will set the user Offline (In the database) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.