# Calculating Total Time Spent by users Online [PHP]



## REY619 (Nov 11, 2007)

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...

```
*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)

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?


----------



## REY619 (Nov 11, 2007)

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)

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.


----------



## REY619 (Nov 11, 2007)

hmm yes, will try and post the results... 
Thanx..


----------



## REY619 (Nov 14, 2007)

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..


----------

