To set the php survival validity period, we can use the session_set_cookie_params function or modify the php. ini file. The following is a brief introduction.
Method 1: session_set_cookie_params
Function prototype void session_set_cookie_params (int $ lifetime [, string $ path [, string $ domain [, bool $ secure = false [, bool $ httponly = false])
| The Code is as follows: |
Copy code |
$ Lifetime = 3600; // one hour Session_set_cookie_params ($ lifetime ); Session_start (); |
Manually set the Session lifetime:
| The Code is as follows: |
Copy code |
Session_start (); // Save for one day $ LifeTime = 24*3600; Setcookie (session_name (), session_id (), time () + $ lifeTime, "/"); ?>
|
Method 2:
If you have operation permissions on the server, it is very easy to set up, but you only need to perform the following steps:
1. Set "session. use_cookies" to 1. Enable the Cookie to store the SessionID. However, the default value is 1, which generally does not need to be modified;
2. Change "session. cookie_lifetime" to positive infinity (of course there are no positive infinity parameters, but there is no difference between 999999999 and positive infinity );
3. Set "session. gc_maxlifetime" to the same time as "session. cookie_lifetime;
4. Modify the php. ini file session. gc. lifetime = 10000