Auto logout timeout using jquery php

I searched and found some examples to set the idle timeout using jquery.

1 - Idle Timeout Eric Hynds DEMO

2 - Idle Timer by paulirish

3 - Fire event when the user is free / DEMO HERE

4 - detect that the user is active or not working on the web page

5 - Comet survey with PHP and jQuery

6 - determining javascript idle timeout

... and a few more similar examples

Between these examples, number 1 is better for me, because I need to automatically log out with any confirmation confirmation after X minutes (logout.php or any URL). but this method is not suitable for the server. The problem is this: this jquery code sends ping to any url: keepAlive.php in a loop / join to query for OK text. see firebug screen:

enter image description here

How to fix it? So other examples just printed Idle / No Idle and do not work with acknowledgment alerts and automatic exit (logout.php or any url) is now really the best way to choose a wait timeout using jquery / Php?

thank

0
source share
3 answers

head X . 20 :

<meta http-equiv="refresh" content = "1200; url=http://www.site.com/user/logout">

, ( ) -, JavaScript .

, (, JS), . JS- .

+3

, JavaScript jQuery. script -, , 25 .

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script type="text/javascript" language="javascript">
  var idleMax = 25; // Logout after 25 minutes of IDLE
  var idleTime = 0;

  var idleInterval = setInterval("timerIncrement()", 60000);  // 1 minute interval    
  $( "body" ).mousemove(function( event ) {
      idleTime = 0; // reset to zero
});

// count minutes
function timerIncrement() {
    idleTime = idleTime + 1;
    if (idleTime > idleMax) { 
        window.location="LogOut.php";
    }
}       
</script>
+1
<script>    
var idleMax = 5;  (5 min)
var idleTime = 0;
(function ($) {

    $(document).ready(function () {

        $('*').bind('mousemove keydown scroll', function () {
            idleTime = 0; 
            var idleInterval = setInterval("timerIncrement()", 60000); 
       });
        $("body").trigger("mousemove");

    });
}) (jQuery)
function timerIncrement() {
     idleTime = idleTime + 1;
     if (idleTime > idleMax) { 
         window.location="Your LOGOUT or Riderct page url here";
     }
 }
</script>
0
source

All Articles