$_SESSION['mySession'] = "mySessionValue";
(Q1) If I set mySession with the code above, how long time is the session alive?
(Q2) How can I set a session which will be alive for 10 minutes?
$_SESSION['mySession'] = "mySessionValue";
(Q1) If I set mySession with the code above, how long time is the session alive?
(Q2) How can I set a session which will be alive for 10 minutes?
Sessions stay alive until the browser is closed, an easy way to keep sessions alive for a specified amount of time is to use either another session or cookie with the current time() and then have your script keep checking against that. So for example
session_start();
if (!isset($_SESSION['currentTime'])){
$_SESSION['currentTime'] = time();
}
if ($_SESSION['currentTime'] < time()-600){
unset($_SESSION['mySession']);
}
(Q1) - session.gc_maxlifetime = 1440
this is the default value in php.ini (in seconds) so after that amount of time garbage collector will clean the session
(Q2) - ini_set(‘session.gc_maxlifetime’, NEW_VALUE);
-> replace NEW_VALUE with the number of seconds you want
if your hosting provider doesn’t allow that and you have an .htaccess enabled folder you could add this to your .htaccess file
php_value session.gc_maxlifetime NEW_VALUE
-> replace NEW_VALUE with the number of seconds you want
I hope this helps