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

查看:24
本文介绍了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天全站免登陆