DIGIT-ARC read-only archive · snapshot: July 23, 2026

Calculating Total Time Spent by users Online [PHP]

6 posts · originally from https://geek.digit.in/community/threads/calculating-total-time-spent-by-users-online-php.72933/

R
REY619 Original post #1
Nov 11, 2007 at 7:41 AM
Can someone give tell me a php script or code to calculate the total time spent by a particular user on the site, from the time of registration till now..
The total time will be shown in the profile of the user....
It may involve both php/mysql if it needs.. I have tried everything but it doesnt sems to work..
If u want to see a demo what i am talking about, see here...
Code:
*www.methos.co.za/login.php?loguid=test&logpwd=test
and click on any profile, there the total online time is shown...
Please help.. :( Thanx..
QwertyManiac
Nov 11, 2007 at 11:06 AM
Um, store the session creation time and then the log-out time and that gives you the total time per session. And just keep adding the calculated time to get the total time?
R
REY619 #3
Nov 11, 2007 at 6:46 PM
Hmm yes, thanx, that could do the trick...
But will the time be updated in real time by this method? Cos the total time will be incremented only when the user logs out or the session expires...
QwertyManiac
Nov 11, 2007 at 8:17 PM
Yeah you're right about that, but the only thing you can do closest to real-time monitoring would be to count the time between each page served to the user and set some averages for log-out/expire time.
R
REY619 #5
Nov 11, 2007 at 10:20 PM
hmm yes, will try and post the results... :)
Thanx..
R
REY619 #6
Nov 14, 2007 at 1:38 PM
I tried doing it, it works, but it only stores the time for a single session. When user logs out, or the session expires, and when the user logs in again, it starts the time again from the starting and the previous online time is lost... :( :(
Tried doing everything but cant figure out the logic..