会话变量消失 [英] Session variables disappearing

查看:152
本文介绍了会话变量消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现会话变量在大约30-90分钟后消失了。我检查会话是否以通常的方式在检索会话变量之前开始:

  function chkSsn(){
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() PHP手册 - phpinfo ,并将输出您的PHP设置。您应该能够从那里解决问题。


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 and session.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屋!

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