laravel会话中的数据持续多长时间? [英] How long does data last in session in laravel?

查看:63
本文介绍了laravel会话中的数据持续多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我注意到我的laravel 5应用程序出现了一个非常令人不安的情况,我似乎无法弄清.登录期间,我像这样

Recently, I have noticed a very disturbing situation with my laravel 5 app which I can't seem to figure out. During login, I set the user_type variable in session like so

Session::put('is_supervisor', $user->is_supervisor);

在我的config/session.php文件中,我具有以下配置:

In my config/session.php file, I have the following configuration:

'lifetime' => 120,
'expire_on_close' => false,

我还实现了记住我"功能.

I have also implemented the remember me functionality.

我以超级用户身份登录,并记得选中了我.几个小时后,我关闭了浏览器而不注销,然后再次启动,因为expire_on_close设置为false并记住我已选中,因此该浏览器已按预期登录用户配置文件.但是,我注意到is_supervisor变量在会话中不再存在,因此我必须注销并再次登录才能使该变量返回会话.可能是什么问题呢?我正在使用文件作为会话驱动程序.

I logged in as a supervisor user with remember me checked. After a few hours, I close the browser without logging out and launch again which logged into the user profile as expected since expire_on_close was set to false and remember me was checked. But, I notice that the is_supervisor variable didn't exist any more in session so I had to logout and login again to have the variable back in session. What could be the problem? I am using file as my session driver.

推荐答案

您需要了解会发生什么情况,将会话的生存期设置为120分钟,然后刷新120分钟.

you need to understand what happen, you set the lifetime of the sessions to 120 minutes, after 120 minutes the session is flushed.

记住我"功能正在使用cookie,因此如果没有用户会话,则对cookie进行检查并在cookie良好的情况下重新创建会话.

the remember me feature is using cookies so if there is no user session than it checked against the cookies and recreate the session if the cookies are good.

我对您的问题是-为什么在会话中存储此数据?如果要检查用户是否为主管,请执行if ($user->is_supervisor)

my question for you is - why do you store this data on session? if you want to check if user is supervisor just do if ($user->is_supervisor)

如果is_supervisor函数内部发生某些数据库查询而不是使用某些缓存机制

if there is some db queries that happen inside the is_supervisor function than use some caching mechanism

这篇关于laravel会话中的数据持续多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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