Yii users being logged out after 15-30 minutes despite session timeouts being set to at least 1 day

后端 未结 5 1770
南笙
南笙 2020-12-08 20:41

I\'ve included the relevent parts of our Yii config file below:

return array(
...
    \'components\'=>array(
        \'session\' => array(
                     


        
5条回答
  •  情深已故
    2020-12-08 21:03

    Try this: first one when you got login you could set setState this:

    yii::app()->user->setState('userSessionTimeout', time() + Yii::app()->params['sessionTimeoutSeconds']); 
    

    add those are text companents.controller.php

     public function beforeAction(){
                // Check only when the user is logged in
                if ( !Yii::app()->user->isGuest)  {
                   if ( yii::app()->user->getState('userSessionTimeout') < time() ) {
                       // timeout
                       Yii::app()->user->logout();
                       $this->redirect(array('/site/login'));  //
                   } else {
                       yii::app()->user->setState('userSessionTimeout', time() + Yii::app()->params['sessionTimeoutSeconds']) ;
                       return true; 
                   }
                } else {
                    return true;
                }
            }
    

    and add those are in config main.php file:

    'params'=>array( 'sessionTimeoutSeconds'=>1800, // 30 minute ),

提交回复
热议问题