Jump to content

Total Time A User Spent Online


Monkuar

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/268970-total-time-a-user-spent-online/
Share on other sites

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.

  • 1 month later...

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

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.