Laravel 5会话生命周期 [英] Laravel 5 Session Lifetime

查看:128
本文介绍了Laravel 5会话生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Laravel config/session.php

According to Laravel config/session.php

/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/

'lifetime' => 120,
'expire_on_close' => true,
'expired-session-redirect' => url(env('APP_URL'))

我已将会话的生存期设置为120分钟,但是我感觉用户在120分钟之前就已注销.

I have set the lifetime of my session to 120 minutes, but I have a feeling that my user is log-out way before 120 minutes.

是错字吗?他们的意思是120秒,即2分钟吗?

Is that a typo ? Do they mean 120 seconds which is 2 mins ?

任何人都可以对此进行说明吗?

Can anyone please shed some lights on this ?

推荐答案

检查您的php.ini:

Check your php.ini for:

session.gc_maxlifetime -默认1440秒-24分钟

session.gc_maxlifetime - Default 1440 secs - 24 mins

session.gc_maxlifetime 指定秒数,在此秒数之后,数据将被视为垃圾"并可能被清除.垃圾收集可能在会话启动期间发生(取决于session.gc_probability和session.gc_divisor).

session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor).

session.cookie_lifetime -默认值0

session.cookie_lifetime 指定发送到浏览器的cookie的生存时间(以秒为单位).值0表示直到浏览器关闭".默认值为0.另请参见session_get_cookie_params()和session_set_cookie_params().

session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0. See also session_get_cookie_params() and session_set_cookie_params().

如果时间少于Laravel配置,则将删除cookie,因为本地php.ini具有对Laravel配置的首选项.

In case it is less time than the Laravel configuration, the cookie will be removed because the local php.ini have preference over Laravel configuration.

您可以增加它或评论/删除.

You can just increase it or comment/delete.

如果未解决,则您的应用程序上的某些内容会破坏会话.

In case is not solved something on your App is destroying the session.

更新

发布后 v5.5.22 会话生存期是从.env,并且不再在config/session.php处进行硬编码,因此更改了

After release v5.5.22 session lifetime is loaded from .env and is not hardcoded anymore at config/session.php, changes there.

现在您可以使用以下方法修改会话生存期:

Now you can modify the session lifetime using:

SESSION_LIFETIME=

在您的.env文件中.

这篇关于Laravel 5会话生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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