phpsessioncookiessession-timeout

Set $_SESSION to expire in 1 month PHP


I am trying to get my $_SESSIONS to expire in 30 days. I do not deal with any sensitive data on my server, so I am not worried about cookie hi-jacking. Would this work?

ini_set('session.cookie_lifetime', 2592000); 
ini_set('session.gc_maxlifetime', 2592000);
session_start();

Solution

  • In addition to your cookie, there are some other settings you need to look at in your php.ini.

    You can manipulate them in code as follows:

    // Current Session Timeout Value
    $currentTimeout= ini_get('session.gc_maxlifetime');
    
    // Change session timeout value for a particular page load  - 1 month = ~2678400 seconds
    ini_set('session.gc_maxlifetime', 2678400);
    

    More here and here