How long does the negative value of this function live isGuest? Does it live until cookies or sessions disappear too? The fact is that it does not work in the basic example. If you have been logged in at least once, and in login ("test", 60); you set the life time of the cookie, then you will still be a pledge, even if you close the browser and open it after 10 years.

  • What about ten years checked? - newman
  • @newman Well, 10 did not check, but three years, yes. - Yuri Svetlov

1 answer 1

In the file /config/params.php set the value

'sessionTimeoutSeconds' => '1800', 

In the controller, where you have the actionLogin () method add:

 Yii::$app->session->set('userSessionTimeout', time() + Yii::$app->params['sessionTimeoutSeconds']); 

Create a beforeAction method in the controller

 public function beforeAction($action) { if (!parent::beforeAction($action)) { return false; } // Check only when the user is logged in if ( !Yii::$app->user->isGuest) { if (Yii::$app->session['userSessionTimeout'] < time()) { Yii::$app->user->logout(); } else { Yii::$app->session->set('userSessionTimeout', time() + Yii::$app->params['sessionTimeoutSeconds']); return true; } } else { return true; } } 

Find the file views / layouts / main.php. At the very top, where meta tags are connected and add title:

 <? if (!Yii::$app->user->isGuest) { ?> <meta http-equiv="refresh" content="<?php echo Yii::$app->params['sessionTimeoutSeconds'];?>;"/> <? } ?> 

A source

  • Although the link can find the answer to the question, it is better to point out the most important thing here, and give the link as a source. If the page to which the link leads will be changed, the response link may become invalid. - From the queue of checks - ermak0ff
  • @Urmuz Tagizade This is not a solution to the problem But thanks anyway - Yury Svetlov
  • @ ermak0ff Thank you. I'm a newbie. Already understood everything) Corrected. - Urmuz Tagizade
  • @Yuriy Svetlov You did everything as I described? Maybe you have flaws in php.ini itself? Check the settings of php.ini, and so the code is working. He himself solved this problem in this way. - Urmuz Tagizade
  • @Urmuz Tagizade and if the user does not want to remember his data? You set the default for all users to save cookies in the browser. - Yuri Svetlov