Yii2从不注销空闲或离开用户 [英] Yii2 Never Logout Idle Or Away User

查看:37
本文介绍了Yii2从不注销空闲或离开用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Yii中的用户关闭了浏览器或闲置了大约一天(可能不确定,我不确定)会自动注销.是否有可能永远不会注销它们(或者至少长时间注销一个月或一年).不确定是否需要更改会话参数或Cookie参数.

User's in Yii appear to be logged out automatically if they close their browser or are idle for about a day (maybe less, I'm not sure). Is it possible to not log them out ever (or at least for a long time for month or year). Not sure if the Session parameters or Cookie parameters need to change.

我尝试更改参数.

'components' => [
    'session'=>[
        'class' => 'yii\web\Session',
        'cookieParams' => ['httponly' => true, 'lifetime' => 3600 * 4* 365],
        'timeout' => 3600*4 *365,
        'useCookies' => true
    ],
]

我已经尝试了会话php ini参数:

I've tried session php ini parameters:

session_set_cookie_params(0);
ini_set('session.gc_maxlifetime', 0);

我尝试设置登录参数

 Yii::$app->user->login($user, 31536000);

推荐答案

您使用的选项应该在没有 timeout useCookies 选项的情况下工作项目,该会话至少需要持续一周的时间,请在Mozilla开发人员栏中打开存储"标签,然后单击左侧的Cookie,您会看到包含已为您的网站注册的Cookie的Cookie部分,在我的情况下为 <代码> http://www.kp2.local

The options you used it should work without timeout and useCookies options, I used it in my last project where the session needed to last for a week minimum, open storage tab in the Mozilla dev bar and click on cookies on the left you will see the cookies section with the cookies registered for your site, in my case it is http://www.kp2.local

如果您使用'lifetime'=>7 * 24 * 60 * 60 ,它应显示 1周后的有效期的cookie,即 2019年1月23日星期三,如下所示

if you use the 'lifetime' => 7 * 24 * 60 * 60, it should show the cookie with an expiry date 1 week later i.e Wed, 23 Jan 2019 like below

,如果您注释掉代码,然后注销,然后再次登录,它应该向您显示 Session 上的到期时间,如

and if you comment out the code and then log out, and log in again it should show you the expiry time on Session like

您只需要在配置中使用以下设置

You just need to use the following settings in the config

'session' => [
    // this is the name of the session cookie used for login on the frontend
    'name' => 'advanced-frontend',
    'cookieParams' => [
        'httpOnly' => true,
        'lifetime' => 7 * 24 * 60 * 60
    ],
],

如果仍然无法使用,请退出系统,尝试尝试通过选择 Delete all (全部删除)选项删除所有cookie,如下图所示.

If it still doesn't work, log out of the system try removing all cookies once by selecting Delete all option like in the image below.

它将起作用.

注意:您应在'lifetime'=>中更改 7 .7 * 24 * 60 * 60,表示要保留会话的天数

Note: You should change the 7 in 'lifetime' => 7 * 24 * 60 * 60, to the number of days you want to keep the session

这篇关于Yii2从不注销空闲或离开用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆