However there are lots of ways in PHP to logout the application when user is idle using session i am using
while login
$_SESSION['last_activity']=time()+10;
in header
$expire_time = 10; //10 secs
if($_SESSION['last_activity'] < time()-$expire_time) {
echo 'session destroyed';
}
else {
$_SESSION['last_activity'] = time();
}
this function logs out the user based on user clicks or refreshing the page even on tabs, but not mouse events which is possible in javascript
var IDLE_TIMEOUT = 900; //seconds
var _idleSecondsCounter = 0;
document.onclick = function () {
_idleSecondsCounter = 0;
};
document.onmousemove = function () {
_idleSecondsCounter = 0;
};
document.onkeypress = function () {
_idleSecondsCounter = 0;
};
window.setInterval(CheckIdleTime, 1000);
function CheckIdleTime() {
_idleSecondsCounter++;
var oPanel = document.getElementById("SecondsUntilExpire");
if (oPanel)
oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
if (_idleSecondsCounter >= IDLE_TIMEOUT) {
alert('Times up!, You are idle for about 15 minutes, Please login to continue');
document.location.href = "logout.php";
}
}
but this wont work across the project or tabs, if user keeps a tab idle and works on another tab the whole project would get logged out, is there any way to make this script works globally or make php to detect all events.