Reputation: 11984
I have a functionality to show alert to logged in user before 10 minutes prior to session expiry.A confirmation will be shown to the user before 10 minutes to the session expiry if he is idle for a specified time.f he wish to continue with the current session he can do that or he can extend the session.So i implemented it like the following.
//For extending the session expiry
public function extendsessionAction(){
$sessTimeOut = 1440;
$session = new Zend_Session_Namespace('Zend_Auth');
$session->reqTime = time();
$session->setExpirationSeconds($sessTimeOut);
$warnTime = 3000;
$session->warnTime = $warnTime;
$this->getHelper('viewRenderer')->setNoRender();
$this->_helper->layout()->disableLayout();
}
//For checking the session expiry
public function checksessionexpiryAction(){
$session = new Zend_Session_Namespace('Zend_Auth');
$reqTime = $session->reqTime;
$warnTime = $session->warnTime;
$sessTimeOut = 1440;
if((time() - $reqTime) >= $warnTime){
echo 'Warning';
}
else if((time() - $reqTime) >= $sessTimeOut){
echo 'Logout';
}
else{
echo 'Continue';
}
$this->getHelper('viewRenderer')->setNoRender();
$this->_helper->layout()->disableLayout();
}
And the following is the client side code used which is written in the header template so it will be included in all the pages
$(document).ready(function(){
extendSessionExpiry();
checkSessionTimeEvent = setInterval("checkSessionExpiry()",8 * 60000);
});
function extendSessionExpiry(){
$.ajax({
url : base_url+'/default/Dashboard/extendsession',
type : 'post',
dataType: 'json',
success : function(result){
}
});
}
function checkSessionExpiry(){
$.ajax({
url : base_url+'/default/Dashboard/checksessionexpiry',
type : 'post',
success : function(result){
if(result == 'Warning'){
showSessionWarning();//Will show a popup to continue or extend the session.Extending the session will call extendSessionExpiry()
}
else if(result == 'Logout'){
dontWarn();
window.location = base_url+'/Index/logout';
}
}
});
}
So i am using zend server in my application.My problem is that if opened the application in more than one tabs then it will go to logout.That means the session is getting expired.I heared that this is something related to zend severs session clustering locking mechanism.Can somebody explain what is the excat problem is.
Upvotes: 1
Views: 637
Reputation: 1076
It should not automatically go to logout.. the server has no idea you have another window/tab open so it will treat them all the same.
I assume that you have tested that it works on it's own, like doing refreshing pages, before opening up a new tab? and then when opening the new tab? Have you tried implementing a way to display how much time they have remaining as they refresh pages... or even a ticker?
I have never heard of Zend terminating a session due to tabs.
Upvotes: 1