I am developing a very front-end driven application based on php,mysql and jquery . This app also requires a User Tracking feature where in the admin can track if the users are currently online or not .
I am using the session expiry time to expire the session after 2 hours and most importantly i am checking if there is any activity on the application via jquery . Below is my code to check the idle time , after which the user will be logged out :
var idleTime = 0;
$(document).ready(function () {
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute
//detect mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime >15) { // 15 minutes of inactivity
window.location.href='logout.php';
}
}
This works perfectly fine if the user has logged in but is idle .
The issue is when the users are not using the browsers . For instance , if a user logs in and closes the browser or the tab then i cannot check if the user is active or logged out or idle .
Would be great if anyone could share their expertise on this one .
Thanks in advance.