Solved

How can I track user idle time

Posted on 2010-08-28
7
488 Views
Last Modified: 2012-05-10
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..
0
Comment
Question by:activesoftware
  • 3
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 250 total points
ID: 33548508
<script type="text/javascript">
var tId="";
document.onmousemove=function() {
  resetTimer();
}
window.onload=function() {
  resetTimer();
}
function resetTimer() {
    clearTimeout(tId);
     tId = setTimeout(function() { location.replace('logout.html') },50000);
 }
</script>
0
 
LVL 12

Expert Comment

by:Rok-Kralj
ID: 33548845
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.
0
 

Author Closing Comment

by:activesoftware
ID: 33549054
Thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 12

Expert Comment

by:Rok-Kralj
ID: 33549140
I don't think you will be driving far with mplungjan's car.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33549152
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?


0
 
LVL 12

Expert Comment

by:Rok-Kralj
ID: 33549337
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."
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33549451
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
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now