To set the php survival validity period, we can use the session_set_cookie_params function or modify the phpini file. The following is a brief introduction. Method 1: session_set_cook
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:
- $ Lifetime = 3600; // one hour
- Session_set_cookie_params ($ lifetime );
- Session_start ();
Run the following code to manually set the Session lifetime:
-
- 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