如何在Laravel中设置会话超时? [英] How to set session timeout in Laravel?
问题描述
是否存在一种固有的方法来设置会话在特定时间后到期.我当前的设置似乎在30分钟后到期,我想禁用它或至少增加它,但是我在Laravel中找不到可以设置此设置的任何地方?
Is there an inherent way to setup sessions to expire after a certain time. My current setup seems to be expiring after 30 minutes and I would like to disable that or at least increase it, but I can't find any places in Laravel where this could be set?
推荐答案
在 app/config/session.php
中,您具有:
寿命
该选项可让您以分钟(而不是秒)设置会话过期时间
option that allow you to set session expire time in minutes (not in seconds)
'lifetime' => 60,
表示该会话将在一个小时后过期.
means that session will expire after an hour.
这里还有另外一个设置:
There is also one more setting here:
'expire_on_close' => true,
决定关闭浏览器时会话是否会过期.
that decides if session will be expired when browser will be closed.
您可能会感兴趣的其他设置也是 php.ini
的值:
Other settings you could get interested is also php.ini
values of:
session.cookie_lifetime = 0
和
session.gc_maxlifetime = 1440
这些是默认值.
第一个表示会话cookie将存储多长时间-默认值为0(直到浏览关闭).第二个选项表示在秒的PHP可能破坏了此会话数据之后.
The first one means how long session cookie will be stored - default value is 0 (until browse is closed). The second option means after how many of seconds PHP may destroy this session data.
我说可能是因为 php.ini
文件中还有一个选项 session.gc_probability
,它决定了运行垃圾收集器的可能性.默认情况下,在1440秒(24分钟)之后,此会话数据将被销毁的可能性只有1%.
I said may because there is one other option session.gc_probability
in php.ini
file that decides what's the chance of running garbage collector. Be default there is only 1% chance that after 1440 seconds (24 minutes) this session data will be destroyed.
这篇关于如何在Laravel中设置会话超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!