authTimeout in Yii2

后端 未结 6 815
余生分开走
余生分开走 2021-01-12 17:22

I am trying to log out user automatically in yii2 after he is idle for a fixed seconds . In web.php I added

\'user\' => [
             


        
相关标签:
6条回答
  • 2021-01-12 17:51

    You can also use

    session.gc_maxlifetime
    

    setting in php.ini

    By default it is 1440 secs.

    0 讨论(0)
  • 2021-01-12 17:57

    $authTimeout - public property.

    The number of seconds in 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 current session expires (c.f. yii\web\Session::$timeout).

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

    0 讨论(0)
  • 2021-01-12 17:58

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

    Your code shall look like this:

    'user' => [
                'identityClass' => 'app\models\User',
                'authTimeout'=>100
            ],
    
    0 讨论(0)
  • 2021-01-12 18:00

    Your config is correct. But it will not automatically refresh your page and show you login form. Technically it will log you out only at the next request after the session is expired. And you should be aware of ajax scripts working on your page and calling some other pages by time interval. Every request will renew your session timeout. There is also "absoluteAuthTimeout" parameter instead of "authTimeout" - that will log you out after the timeout despite of your activity.

    0 讨论(0)
  • 2021-01-12 18:03

    if you want log out user after X time. You should check with ajax each second. If expired redirect to log out

    0 讨论(0)
  • 2021-01-12 18:10

    In your config/web.php file:

    In $config array:

    ...

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

    ...

    Please note I commented the //enableAutoLogin, that prevents of authTimeout to work properly

    0 讨论(0)
提交回复
热议问题