tyebillion tyebillion - 1 year ago 91
Apache Configuration Question

Session variables disappearing

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)

I am setting the session variables as follows:

function setSsnVar($nm, $vlu) {
$_SESSION[$nm] = $vlu;

And retrieving them as follows:

function ssnVar($nm) {
if (array_key_exists($nm, $_SESSION))
return $_SESSION[$nm];
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download