jquery - How to keep alive a user's session while they are posting on a forum? -
i have site session timeout of 15 minutes. on pages user spends longer 15 minutes filling in reply. best solution keep alive session in case?
i use jquery
on these pages, possibly pinging server, on events?
the backend struts
on tomcat
.
given don't want change site's session timeout..
set timeout/interval (< 15min) event in javascript , decide when event triggers. if want session active long page open, fine, keep pinging every < 15 min. that's not want user leaving public computer should logged out @ point.
you maintain variable lastactivity
, updated on each document mousemove or document keydown. if there's been activity since last ping, ping again.
to more sophisticated, count events , ping server if number of events > threshold @ timeout.
the basic example:
setinterval(function(){ $.get('/imstillalive.action'); }, 840000); // 14 mins * 60 * 1000
with basic check typing activity:
$(function(){ var lastupdate = 0; var checkinterval = setinterval(function(){ if(new date().gettime() - lastupdate > 840000){ clearinterval(checkinterval); }else{ $.get('/imstillalive.action'); } }, 840000); // 14 mins * 60 * 1000 $(document).keydown(function(){ lastupdate = new date().gettime(); }); });
Comments
Post a Comment