Session time setting this post was last edited by guliputaoyou in 2013-04-2311: 04: 18 because I cannot change the server configuration file, but I need to modify the user login time to 2 h. So I phpinfo and found gc_maxlifetime1440, so I checked a lot of information and used this function on the login page to replace the original session_st session time settings.
This post was last edited by guliputaoyou at 11:04:18
Because I cannot change the server configuration file, I need to change the user logon time to 2 h.
So I phpinfo and found that gc_maxlifetime = 1440,
So I checked a lot of information and used this function on 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 setting $ expire to 36000 (10 h) still does not work.
In addition, there are a lot of session_start in a bunch of old code. do you want to replace all of them with start_session_custom?
I can only change it on the first session_start page (that is, the logon page?
Correct the following:
The full text shows that session_set_save_handler exists.
Where
While $ maxlifetime = 72000;
Function gc ($ maxlifetime)
{
If (rand (1000) %! = 0) return false;
$ Expiretime = $ this-> now-$ maxlifetime;
Return $ this-> db-> query ("delete from $ this-> table WHERE 'Last _ active' <$ expiretime ");
}
------ Solution --------------------
The principle is: set before session_start; otherwise, it is invalid.
You can put your code in a public file (all programs will load it), and delete session_start from other files.
If you find it troublesome, you can run your project in the php 5.4 environment.
Php 5.4 will issue a warning to the recurring session_start, so it is convenient to modify it accordingly.