xxxxxxxxxx
24 minutes
It depends on the server configuration or the relevant directives session. gc_maxlifetime in php. ini . Typically the default is 24 minutes (1440 seconds), but your webhost may have altered the default to something else
xxxxxxxxxx
<?php
//Set the session timeout for 2 seconds
$timeout = 2;
//Set the maxlifetime of the session
ini_set( "session.gc_maxlifetime", $timeout );
//Set the cookie lifetime of the session
ini_set( "session.cookie_lifetime", $timeout );
//Start a new session
session_start();
//Set the default session name
$s_name = session_name();
//Check the session exists or not
if(isset( $_COOKIE[ $s_name ] )) {
setcookie( $s_name, $_COOKIE[ $s_name ], time() + $timeout, '/' );
echo "Session is created for $s_name.<br/>";
} else {
echo "Session is expired.<br/>";
}
?>
xxxxxxxxxx
// Set the session timeout to 1 hour
ini_set('session.gc_maxlifetime', 3600);
// Start the session
session_start();