会话变量消失 [英] Session variables disappearing
问题描述
function chkSsn(){
PHP手册 - phpinfo ,并将输出您的PHP设置。您应该能够从那里解决问题。
if(session_status()== PHP_SESSION_NONE)
session_start();
$ b我设置会话变量如下:
函数setSsnVar($ nm,$ vlu){
chkSsn();
$ _SESSION [$ nm] = $ vlu;
$ / code>检索它们如下:
函数ssnVar($ nm){
chkSsn();
if(array_key_exists($ nm,$ _SESSION))
return $ _SESSION [$ nm];
else
return;
$ b $ p
$ b我试着在session_start之后立即添加下列行, (b)
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $'
header(Pragma:no-cache);
我使用Firefox 48,Apache / 2.4.7(Ubuntu)和PHP版本5.5.9- 1ubuntu4.19。
解决方案由于php中的设置,会话数据可能会在客户端浏览器或服务器中超时。 INI。标准设置是:
session.cookie_lifetime
和session.gc_maxlifetime
。实际上,还有一些控制会话生存时间的重要设置,所以我强烈建议这个 phpinfo()I am finding that session variables are disappearing after about 30 - 90 minutes. I check that the session has been started in the usual way before retrieving a session variable:
function chkSsn() { if (session_status() == PHP_SESSION_NONE) session_start(); }
I am setting the session variables as follows:
function setSsnVar($nm, $vlu) { chkSsn(); $_SESSION[$nm] = $vlu; }
And retrieving them as follows:
function ssnVar($nm) { chkSsn(); if (array_key_exists($nm, $_SESSION)) return $_SESSION[$nm]; else return ""; }
I tried adding the following lines immediately after "session_start", but it didn't make any difference:
header("Cache-Control: no-cache"); header("Pragma: no-cache");
I am using Firefox 48, Apache/2.4.7 (Ubuntu) and PHP Version 5.5.9-1ubuntu4.19.
解决方案Your session data may be timing out within the client browser or on the server due to settings in php.ini. The standard settings are:
session.cookie_lifetime
andsession.gc_maxlifetime
. In fact, there are additional important settings that control session lifetime, so I highly recommended this article.So create a simple php page that calls the function
phpinfo()
PHP Manual - phpinfo and that will output your php settings. You should be able to resolve the issue from there.这篇关于会话变量消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!