尽管有用户活动,会话仍将在 Yii2 中过期 [英] Session expiring in Yii2 despite user activity

查看:34
本文介绍了尽管有用户活动,会话仍将在 Yii2 中过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用 Yii2 并且需要在身份中存储有关用户的更多信息.我已经知道在 Yii2 中,这应该使用像

I have started using Yii2 and need to store more information about user in identity. I already know that in Yii2, this should be done using sessions like

Yii::$app->session->set('user.company_id', '121');

这很好用,因为我可以稍后在项目中使用以下方法获取这些值:

This works fine as I am able to get these values later in project using:

Yii::$app->session->get('user.company_id');

.但是,尽管用户在同一页面上进行了活动,但这些会话值还是会被清除.因此,在 5-10 分钟后,同一用户会看到一些基于会话值的字段,但是,1 分钟后,如果我刷新会话值就会消失,这实际上应该在会话关闭或用户注销时发生.

. However, these session values are getting wiped up despite user activity on same pages. So after 5-10 minutes, the same user sees some fields based on session value, however, after 1 minute if I refresh the session values go away which should actually happen on session close or user logout.

任何建议我做错了什么?

Any suggestions what I am doing wrong?

推荐答案

首先检查你的 app\config\main.phpmain-local.php 是否包含:

First check your app\config\main.php or main-local.php if it contains:

'user' => [
    ...
    'enableAutoLogin' => true,
    ...
],

第二次检查您是否对分配给变量的值进行了正确的赋值:

Second check if you have a proper assignment to the value assigned to the variable:

$authTimeout;
$absoluteAuthTimeout;

请参阅此处了解更多信息.

这篇关于尽管有用户活动,会话仍将在 Yii2 中过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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