问题描述
所以我遇到了这个问题,当我在页面上一段时间没有做任何事情时,在我重新加载页面后 $_SESSION
被清除.我检查了代码,它没有任何 unset()
函数或其他任何可以清除 $_SESSION
变量的东西.任何想法为什么会发生?
So I've this problem that, when I'm on the page not doing anything for some time, after I reload the page $_SESSION
is cleared. I checked the code and it does not have any unset()
functions or anything else what could clear the $_SESSION
variable.Any ideas why is it happening?
如果我想让会话一直持续到浏览器关闭,我该怎么办?我不理解它,因为 gc
检查会话是否在 session_start
上过期,但是在调用 session_start
之前我无法修改会话数据,所以在调用 session_start
之后修改会话数据会导致会话过期吗?
In case if I want to make the session live till the browser is closed what should I do? I don't understand it as the gc
checks if session is expired on session_start
, but I can't modify the session data before calling session_start
, so modifying the session data after calling session_start
would result in expired session anyway?
我将 session.cookie_lifetime
默认设置为 0,session.gc_maxlifetime
、session.gc_divisor
、session.gc_probability
也设置为其默认值.
I've the session.cookie_lifetime
set to 0 by default, session.gc_maxlifetime
, session.gc_divisor
, session.gc_probability
are set to their default values too.
推荐答案
你有没有把de session_start()
放在每一页的开头?
Have you put de session_start()
at the beginning of every page?
这篇关于为什么 PHP 会话在页面重新加载时被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!