AuthTimeout in Yii2

I try to automatically log out in yii2 after it has been idle for fixed seconds. In web.php I added

 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, 'authTimeout'=>100 ], 

inside components . I am using a basic template. But it does not exit the system automatically. Does it work in Yii2? I followed the documentation from http://www.yiiframework.com/doc-2.0/yii-web-user.html

+6
source share
6 answers

$authTimeout is a public property.

The number of seconds during which the user will be logged out automatically if he remains inactive. If this property is not set, the user will be logged out after the expiration of the current session (cf yii\web\Session::$timeout ).

Note that this will not work if $enableAutoLogin is true .

+4
source

Your configuration is correct. But it will not automatically refresh your page and show your registration form. Technically, it will only log out at the next request after the session expires. And you should be aware of the ajax scripts running on your page and call up some other pages on a time interval. Each request will extend the session timeout. There is also the "absoluteAuthTimeout" parameter instead of the "authTimeout", which will exit the system after a timeout, despite your activity.

+1
source

In your config/web.php :

In the $config array:

...

 'user' => [ 'identityClass' => 'app\models\User', //'enableAutoLogin' => true, 'enableSession' => true, 'authTimeout' => 60, ], 

...

Note that I commented on //enableAutoLogin , which prevents authTimeout from working authTimeout

0
source

You can also use

 session.gc_maxlifetime 

in php.ini

The default is 1440 seconds.

0
source

if you want to log out after X-time. You have to check with ajax every second. If the forwarding period for logout has expired

0
source

Just remove "enableAutoLogin" from your user configuration and it will work fine.

Your code will look like this:

 'user' => [ 'identityClass' => 'app\models\User', 'authTimeout'=>100 ], 
0
source

Source: https://habr.com/ru/post/986645/


All Articles