yii2 闲置 5 分钟后自动注销

Automatic Logout after 5 minutes of inactive in yii2

请问yii2如何设置用户闲置时间超过5分钟自动退出的功能?

您的答案在于配置文件中 "user" 组件的配置。

您需要知道的一切都在本文档中 Yii2 User Component,将 authTimout 属性 设置为 300(以秒为单位),您的用户应该在 5 分钟不活动后注销。

试试这个配置:

'user' => [
        'enableAutoLogin' => false,
        'authTimeout' => 300,
    ],

authTimeout

在您的组件配置中,您需要像这样在用户组件中添加配置

'components'=>[
        'user' => [
            'class'=>'yii\web\User',
            'identityClass' => 'common\models\User',
            'loginUrl'=>['sign-in/login'],
            'enableAutoLogin' => false,
            'authTimeout'=>300,  //Number of second to Automatic Logout if inactive
            //this config is optional
            'identityCookie' => [
                'name' => '_backendUser', // unique for backend
                'path'=>'@backend/web'  // correct path for the backend app.
            ],
            'as afterLogin' => 'common\behaviors\LoginTimestampBehavior'
        ],
    ],