1

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.

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
  • When session is started for logged user (for example in login action), variable "reqTime" is setup in session? – Alexander Nov 09 '13 at 10:17
  • Not like that @Alexander. After login whenever the user refreshes any page then that time will be setup as `reqTime`.So it will happen whnever the user refreshes the time after login – 웃웃웃웃웃 Nov 09 '13 at 10:20

1 Answers1

1

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.

MrJustin
  • 1,056
  • 7
  • 9
  • Every time when a page is loaded i am sendng that ajax to the server to update last request time.So every time server will know about it and update the request time in session.And its not about `Zend terminating a session due to tabs` its about session cluster locking inn zend server – 웃웃웃웃웃 Nov 16 '13 at 08:09
  • That is correct, however, the server has no idea that you have opened another tab or window. For all it knows, you just clicked on a new link. – MrJustin Nov 16 '13 at 08:11
  • Yes obiviously.But since there are so many requests going to the server simultaneously and each request is trying to write some data into same session variable the problem is happening.Because each time when the data is writing to the session it locks session to prevernt data getting corrupted.That might be the problem. – 웃웃웃웃웃 Nov 16 '13 at 08:20