要使会话保持活动状态大约两天,需要哪些php.ini设置? [英] What php.ini settings are required to allow a session to remain active for approximately two days?

查看:98
本文介绍了要使会话保持活动状态大约两天,需要哪些php.ini设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://www.php。 net / manual / en / session.configuration.php#ini.session.cookie-lifetime

表示session.cookie_lifetime为0直到浏览器已关闭。是会话可以具有的绝对最大长度(在关闭浏览器时总是擦除),还是设置一个会话。cookie_lifetime为23243245234,会导致结果可能会持续到关闭浏览器时?

says that a session.cookie_lifetime of 0 "goes until the browser is closed". Is that the absolute maximum length that the session can have (always wiped when the browser is closed), or would setting a session.cookie_lifetime of, say, 23243245234 yeild a result that would probably last beyond whenever the browser is closed?

更重要的是,我需要设置什么php.ini设置才能使会话持续两天,并且出于安全考虑,建议使用某些(我希望可以有较低的时间限制,如果可以,建议的期限是什么?

More to the point, what php.ini settings would I need to set to make sessions last somewhere along the lines of two days, and is there a security reason to recommend a certain (I would expect lower) time limit, and if so what would the recommended period be?

预期的行为
编辑:这是我想要实现的目标,也许我可以通过获取一些设置建议(而不是php.ini设置的特定值)来理解行为:

Intended behavior Here is what I want to achieve, perhaps I'll be able to understand the behavior by getting some settings suggestions as opposed to the specific values of the php.ini settings:

I希望会话尽可能长地持续,最多(大约)两天。
如果会话可以持续到关闭浏览器之外,我希望这样做(最多约两天)。

I want the session to last as long as possible, up to (approximately) two days. If the session can last beyond browser close, I would like it to do so (up to approximately two days).

我将为php设置什么。 INI设置(是的,我可以直接编辑php.ini)来达到目的?

What would I set for php.ini settings (and yes, I have direct edit access to the php.ini) to acheive that?

推荐答案

有两个参数您需要担心有关会话。第一个是cookie的TTL,另一个是会话数据文件在被垃圾回收之前可以老化多久。

There are two parameters you need to worry about regarding sessions. The first is the TTL for the cookie, the other is how old a session data file can become before it gets garbage collected.

session.cookie_lifetime确定发送到浏览器的cookie的持续时间(以秒为单位)。默认为0,表示直到浏览器关闭。需要两天的时间为172800秒。

session.cookie_lifetime determines, in seconds, how long the cookie sent to the browser will last. It defaults to 0, which means until the browser closes. For two days it'd need to be 172800 seconds.

session.gc_maxlifetime还可以以秒为单位确定服务器上标记的会话数据将被视为垃圾多长时间。并可以删除。

session.gc_maxlifetime determines, also in seconds, how long before session data marked on the server will be regarded as garbage and can be deleted.

设置这两个ini指令应使您的会话可以生存两天,除了您需要注意的另一件事。

Setting these two ini directives should give you sessions that survive for two days, except for one more thing of which you need to be aware.

某些操作系统会在其默认临时目录上进行自动垃圾回收。如果将PHP配置为在此处存储会话数据,则如果temp目录的GC周期很短,则您可能会在达到session.gc_maxlifetime中的值之前丢失自己的会话。为避免这种情况,请确保PHP将会话数据存储到/ tmp以外的其他位置,或主机操作系统的临时目录中。

Some operating systems do automated garbage collection on their default temporary directories. If PHP is configured to store session data there, then if the GC period for the temp directory is short you may find yoruself losing your session before the value in session.gc_maxlifetime is reached. To avoid this, make sure PHP is storing session data to a location other than /tmp or whatever the temporary directory of your host operating system is.

这篇关于要使会话保持活动状态大约两天,需要哪些php.ini设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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