Forum Moderators: coopster

Message Too Old, No Replies

calculate and display user's logged in time

         

fastcreators

9:54 am on Aug 15, 2005 (gmt 0)



i want to calculate the time for which the user remains logged in on my site, for example if user A logs in at 10 am and logs off at 10:15 am then store 15 minutes time and if he agains logs in then also calculate that time and add to this 15 minutes and shows his total time in the system.

ryan26

10:57 am on Aug 15, 2005 (gmt 0)

10+ Year Member



The problem there is the user triggering the "exit" for you to track, which would either come via clicking a "log out" link, the best scenario for you, or by simply browsing away from the webpage. I'm not quite sure if it's possible to trigger something when the user browses away cleanly. Maybe somebody else can chime in on that.

Without digging too deep into programming something yourself, various server logs will track time spent on a webpage and will use the last time an HTTP request was handled as the "exit" time, I think. It should at least give you some pretty reliable data that can be used comparatively. You probably don't want too-the-second data across a big volume website, anyway.

dreamcatcher

11:21 am on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use javascript to detect when a user leaves your website. You might have seen some sites use a 'Thanks for visiting my site' pop up when you exit. Maybe you could use something like that to trigger the exit time.

dc

fastcreators

6:26 pm on Aug 15, 2005 (gmt 0)



hmm thanks for your suggestions, Devshed Forums have this script they show the members spent time amount so thats why i asked this i thought they are doing this with php.though i will look into java script and some servers tricks to calculate that,
thanks for your suggestions

jatar_k

6:36 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the other thing is they might not actually have the full time.

the scenario could be

user logs in and they set the time in the session. Every time they hit a new page it can calculate the time passed since the 'last hit' in the session and add it to the session var 'total time' then update 'last hit' to now().

repeat every time they hit a page.

when they leave, who cares don't worry about it. That's as accurate as you need to be.

most login scripts should check session time already so it should be a small change to display this.

fastcreators

10:46 am on Aug 16, 2005 (gmt 0)



yea thats a cool suggestion i will surely work over this, thanks for so rapid and informative posts.