php Laravel 5 会话生命周期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41983976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:31:33  来源:igfitidea点击:

Laravel 5 Session Lifetime

phpsessionlaravel-5

提问by cyber8200

According to Laravel config/session.php

根据 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'))

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

我已将会话的生命周期设置为120分钟,但我感觉我的用户在 120 分钟之前注销了。

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

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

Can anyone please shed some lights on this ?

任何人都可以对此有所了解吗?

回答by Troyer

Check your php.ini for:

检查您的 php.ini:

session.gc_maxlifetime- Default 1440 secs - 24 mins

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

session.gc_maxlifetimespecifies 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.gc_maxlifetime指定数据将被视为“垃圾”并可能被清理的秒数。会话启动期间可能会发生垃圾收集(取决于 session.gc_probability 和 session.gc_divisor)。

session.cookie_lifetime- Default 0

session.cookie_lifetime- 默认 0

session.cookie_lifetimespecifies 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().

session.cookie_lifetime指定发送到浏览器的 cookie 的生命周期(以秒为单位)。值 0 表示“直到浏览器关闭”。默认为 0。另见 session_get_cookie_params() 和 session_set_cookie_params()。

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

如果比 Laravel 配置时间少,cookie 将被删除,因为本地 php.ini优先于 Laravel 配置。

You can just increase it or comment/delete.

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

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

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

UPDATE

更新

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

v5.5.22 版会话生存期从 加载.env并且不再硬编码后,在那里config/session.php发生了变化。

Now you can modify the session lifetime using:

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

SESSION_LIFETIME=

In your .envfile.

在您的.env文件中。

回答by Alireza Bijantabar

Change .envfile in your app root

更改.env应用根目录中的文件

SESSION_LIFETIME=120

And value is in minutes.

价值以分钟为单位。