Monkuar Posted October 1, 2012 Share Posted October 1, 2012 I am not looking for coding just advice on how to do it. I want to show users total time spent online. First i'll add a row into my users table, but then how would I go about storing the time in their? When the online function deletes everyone from the list, make it add the total amount of seconds they were online? (That will be stored in a session or what?) Thanks also should the row be a int 10, and then just store the seconds in their and increment it or wat? Quote Link to comment https://forums.phpfreaks.com/topic/268970-total-time-a-user-spent-online/ Share on other sites More sharing options...
ManiacDan Posted October 1, 2012 Share Posted October 1, 2012 Storing time spent online is always an estimate. You can never tell when they leave the site, or if the human is still at the keyboard doing things. You can just say that every page load represents 30 seconds online, then keep a page load counter in the user table. Quote Link to comment https://forums.phpfreaks.com/topic/268970-total-time-a-user-spent-online/#findComment-1382079 Share on other sites More sharing options...
The Little Guy Posted October 1, 2012 Share Posted October 1, 2012 I would do something similar to this: http://phpsnips.com/snip-39 The code would need to be canged to instead of logging a user out, disable the counter till they load a new page. Quote Link to comment https://forums.phpfreaks.com/topic/268970-total-time-a-user-spent-online/#findComment-1382119 Share on other sites More sharing options...
mrMarcus Posted November 27, 2012 Share Posted November 27, 2012 With a simple Javascript setInterval() and some AJAX, you can make something that will suit your needs just fine. I am not looking for coding just advice on how to do it. I want to show users total time spent online. First i'll add a row into my users table, but then how would I go about storing the time in their? When the online function deletes everyone from the list, make it add the total amount of seconds they were online? (That will be stored in a session or what?) Thanks also should the row be a int 10, and then just store the seconds in their and increment it or wat? A combo of Javascript, AJAX, and PHP should suffice. Use Javascript's setInterval() to "ping" the user's current state. If user has been inactive for x seconds/minutes/whatever, stamp that time and redirect to login page. With setInterval() you can get right down to (almost) exact time; however, that is just a waste. Really the setInterval() should work in hand with the allowable length of your current sessions. My $0.02 Quote Link to comment https://forums.phpfreaks.com/topic/268970-total-time-a-user-spent-online/#findComment-1395677 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.