Session time setting
This post was last edited by guliputaoyou on 2013-04-23 11:04:18
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");
}
------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.