Web development basic and advance tutorial, php basic tutorial, laravel basic tutorial, React Native tutorial

Sunday, September 6, 2020

Log out automatically when there is no use of Keyboard or Mouse

0 comments

 
Log out automatically when there is no use of Keyboard or Mouse

in this tutorial i will explain how you can manage session in php if someone has no
movment in that website.

Lets Start the work. how we can slove this.

When i do not use keyboard and mouse for a particular time limit (Like 10 min or 20 min)
at that time it should log out User automatically from the current session. 

Please give me any suggestion or code in PHP.
You need javascript to detect browser events.
With jQuery, something like (untested)
<script type="text/JavaScript">
$(document).ready(function() { 
// alert('Footer');
});
var timeSinceLastMove = 0;
$(document).mousemove(function() {
//alert('Mouse');
    timeSinceLastMove = 0;
});
$(document).keyup(function() {
    timeSinceLastMove = 0;
});
checkTime();
function checkTime() {
//alert('Check Time');
    timeSinceLastMove++;
  //  if (timeSinceLastMove > 10 * 60) {
    if (timeSinceLastMove > 5 * 60) { // 5 mints
        window.location = "checklogout.php";
    }
    setTimeout(checkTime, 1000);
}
</script>


No comments:

Post a Comment