0

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.

gornvix
  • 3,154
  • 6
  • 35
  • 74
  • 1
    Maybe [this question](http://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php) might help? – Henders Aug 15 '16 at 13:05

1 Answers1

2

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.

Trialsman
  • 329
  • 3
  • 14