Link to home
Start Free TrialLog in
Avatar of activesoftware
activesoftware

asked on

How can I track user idle time

Hi,

I would like to know how can I track whether there has been any activity from user on my site , that is basically what I want to do is if user has not clicked any link say for 5 minutes user should be logged out.

Thanks..
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For each user, keep field last_action in the database.

On each page, first check if time() - $db['last_action'] is bigger than 5*60, and if, log the user out, otherwise update last action to current time.

This is far better solution that one above, because it is solved on the server side and user cannot interfere with it.
Avatar of activesoftware
activesoftware

ASKER

Thanks
I don't think you will be driving far with mplungjan's car.
Strange comment. Why would it not be perfectly ok to detect on the client that the user of the page on the client has not done anything on the client? You solution is server intensive, needs at least a session whereas mine just needs a tiny script in an external js file in the head of the page, can be included from the server or not depending.

If the user never clicks on anything, how are you planning to kick them to the homepage automatically? Using server push?


Yes, it indeed has a pros that it detects also mouse movement. But that is easily spoofable. How can you be sure that user even has a javascript on?

Server intensive, come on :) And your comment comment about needing at least a session - how can you even log out without a session :) You need a session anyway.

Your script is intensive with resources (thou not server's), because it calls resetTimer() for every pixel mouse pointer moves. I approximate up to 100 calls per second.

No, if user doesn't click anything for 5 minutes, I'm just going to display them a message: "Your session has expired due to 5 minute inactivity. Please log on again."
Seems the asker is not worried about spoofing, just want the user to go away if he does nothing on his site.

User can also ping your server with some ping script

Both solutions work in my opinion