Since I cannot change the server configuration file, I need to modify the time to keep the user logged in at 2h.
So I phpinfo a little bit and found gc_maxlifetime=1440,
So a lot of data, the function is used in the login page, to replace the original session_start ().
function Start_session_custom ($expire = 36000)
{
Ini_set (' Session.gc_maxlifetime ', $expire);
if (Empty ($_cookie[' Phpsessid ')) {
Session_set_cookie_params ($expire);
Session_Start ();
} else {
Session_Start ();
Setcookie (' Phpsessid ', session_id (), time () + $expire);
}
}
Although the $expire is set to 36000 (10h), it still does not work.
Another: a bunch of old code there is a lot of session_start, is it necessary to replace all the Start_session_custom?
I only change the first Session_Start page (that is, the login page).
To correct:
Read the full text and find Session_set_save_handler.
which
and $maxlifetime=72000;
Function GC ($MAXLIFETIME)
{
if (rand (0,1000)%1000!=0) return false;
$expiretime = $this->now-$maxlifetime;
return $this->db->query ("DELETE from $this->table WHERE ' last_activity ' < $expiretime");
}
Reply to discussion (solution)
The principle is: set before session_start, otherwise invalid
You can put your piece of code in a public file (all the programs will load his type), and delete the session_start from the other files.
If you find it troublesome, then you can run your project in a PHP 5.4 environment.
PHP 5.4 warns of recurring session_start, which makes it easy to modify.
The code visible from Start_session_custom is indeed set before session_start.
My idea is that the login page calls Start_session_custom for the first time, and then the subsequent session will use the Gc_maxlifetime set in Start_session_custom.
So the reason for the failure is still the session_start on the back page?
Settings that are made in the program expire at the end of the program