Session 用户空闲固定秒后,如何在yii2中自动注销用户

Session 用户空闲固定秒后,如何在yii2中自动注销用户,session,yii2,Session,Yii2,我使用的是Yii2,我想在固定空闲秒后,用户自动注销并重定向到登录页面 我已经试过了 'components' => [ 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, 'authTimeout' => 60, ] ], 我该怎么办 您的“用户”是否有“

我使用的是Yii2,我想在固定空闲秒后,用户自动注销并重定向到登录页面

我已经试过了

 'components' => [
    'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
             'authTimeout' => 60,
        ]
    ],
我该怎么办

  • 您的“用户”是否有“loginUrl”属性? 看

    “用户”=>[ 'loginUrl'=>['site/login']]

  • 您的控制器是否具有要求经过身份验证的用户执行的操作的规则? 看


  • 您可以将JavaScript函数设置为每分钟左右运行一次,以进行ajax调用并检查当前用户的会话是否已过期。然后,您可以使用以下JavaScript重定向:

    window.location("example.com/login");
    

    不要将
    enableAutoLogin
    设置为
    true
    。使用以下配置:

    ...
    'user' => [
            'identityClass' => 'backend\models\Users',
            'enableSession' => true,
            'authTimeout' => 300,
       ],
    ....
    // below is documentation from source code for authTimeout
    
    /**
     * @var integer 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. [[Session::timeout]]).
     * Note that this will not work if [[enableAutoLogin]] is true.
     */
    

    禁用自动登录:我试过了,但并没有重定向到登录页面