I have a web application made in Code igniter. What it basically does is -
My Question - While JavaScript timer is running, can we prevent session timeout, so that users are not logged out and their progress is not lost?? My initial thought is that it can't be, at least there isn't an easy way because we are dealing with Javascript timer (Client) and the Session timeouts (server).
Thanks in advance
Throughout the timer session keep sending keepalive request every some minutes(preferred 2 to 5 minutes)
This keepalive request will be the as light as possible and will only get session on the server and will keep it alive
The response will be also as simple as something like session is still active kind of thing...
On the other hand you could also maintain a variable on javascript side usersLastActivity, which is updated on each document mousemove or document keydown and few events. If there's been any activity since last request, then send keepalive request ...
To get more idea about you can have a look at other same kind of question posted here.
The basic example:
setInterval(function(){
$.get('/ImStillAlive.action');
}, 300000); // 5 mins * 60 * 1000
With basic check for typing activity:
$(function(){
var lastUpdate = 0;
var checkInterval = setInterval(function(){
if(new Date().getTime() - lastUpdate > 300000){
clearInterval(checkInterval);
}else{
$.get('/ImStillAlive.action');
}
}, 300000); // 5 mins * 60 * 1000
$(document).keydown(function(){
lastUpdate = new Date().getTime();
});
});