1

I am trying to avoid session expiration if user does not refresh the page more than 24 minutes e.g. is writing an article. I am sending an ajax request every 19 minutes.

setInterval( function() 
{
  $.ajax({
    type: 'POST',
    url: {link :Helper:default},
    accepts : 'json',
    complete: function( jqXHR ) 
    {
      if( jqXHR.status == 200 ) 
      {
           console.log( jqXHR.responseJSON.message );
      }
      else 
      {
           alert( 'After few minutes you will be logged out due the browser inactivity.' );
      }
    }
  });
}, 1000 * 60 * 19 );

But it does not work as I expect. If the interval is e.g. 5 minutes it works well, server returns json object with status 200 but it seems that session is not extended cause after 24 mins i am logged out however. Can you explain it to me please? I don't understand where is the problem.

Čamo
  • 3,863
  • 13
  • 62
  • 114
  • It could be that your server connectivity or session might expire before 24 mins. Since there is no request to the server for 24mins, and your server could be configured with a default session timing less than 24mins, hence you are logged of. You could send a request to the server every 5 mins if there is no browser inactivity for 5 mins. – debatanu Sep 16 '15 at 14:32
  • I have written there that if I send request every 5 mins it returns status 200 but after 24 mins I am however logged out. Can you explain it better? – Čamo Sep 16 '15 at 14:36
  • What user3081756 is trying to say is that the session appears to be expiring before the 24 (or your 19) minute interval you describe. Personally I'd advise against this approach, as this would keep the session active for as long al the page is open (which could let you run out of sessions). Add some kind of (scoped) variable wich indicates activity, for example based on a `key` event. – Rogier Spieker Sep 16 '15 at 14:50
  • What scoped variable? In php.ini is session.gc_maxlifetime = 1440. Why the session expires however I do ajax request? – Čamo Sep 16 '15 at 15:11
  • I am sorry, I had a bad setting of sessions in framework... – Čamo Sep 26 '15 at 21:06

0 Answers0