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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.