Jump to content

session timeout(maxlifetime)


stockton

Recommended Posts

I have written a little program which appears to work fine but.....

The code looks like:-

<?php
    session_start();
// Get the current Session Timeout Value
    $currentTimeoutInSecs = ini_get('session.gc_maxlifetime');
        echo "\nDefault timeout = ".$currentTimeoutInSecs." seconds\n";

    // Change the session timeout value to 30 minutes
    ini_set('session.gc_maxlifetime', 30*60);
    $currentTimeoutInSecs = ini_get('session.gc_maxlifetime');
        echo "Altered timeout = ".$currentTimeoutInSecs." seconds\n";
?>

and this appears to work fine except that the second time I run it I would expect to see the default time altered to what I set it to rather than what it was in the 1st place.

No matter how many times I run it the results are always:-

Default timeout = 1440 seconds

Altered timeout = 1800 seconds

Please tell me why.

Link to comment
https://forums.phpfreaks.com/topic/92262-session-timeoutmaxlifetime/
Share on other sites

ini_set() statements only changed the setting for the duration of the script.

 

From the ini_set() section of the php manual -

The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

 

You must also set any session settings before the session_start() for them to affect that session.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.