This topic is locked
[SOLVED]

 In case of user inactivity

11/17/2020 11:17:53 AM
PHPRunner General questions
A
alghanim author

If the user is inactive on the page, force the user to log off.

Is this code correct?



var idleTime = 0;

var start = new Date();

var end;
$(document).on('mousemove keydown click', function() {

end = new Date();

idleTime = (end.getTime() - start.getTime()) /1000;

// 30 seconds of idle time

if ( idleTime > 30 ) {





window.location.href = "login.php?a=logout";
}

});
Sergey Kornilov admin 11/17/2020

Did you try this code? What work and what doesn't work?
I can tell that if user simply leaves this page open and go away they will be never logged out because they don't move their mouse or click anything.

A
alghanim author 11/17/2020

thank you for caring

It works but is useless.

When a record is added, it is logged off before completion

I expect it is annoying

It can only be used for the home page