How to modify the session lifetime in php: You can use the ini_set function to modify it, such as [ini_set('session.gc_maxlifetime',21600);]. It should be noted that this setting will be cleared when the script execution ends.
Method 1: Modify the configuration file php.ini
(Related learning video recommendations: java video tutorial)
php.ini About Session-related settings (open the php.ini file, in the "[Session]" section):
1. session.use_cookies: The default value is "1", which means SessionID is passed using Cookie, otherwise it is passed using Query_String;
2. session.name: This is the variable name stored in SessionID, which may be Cookie or Query_String. The default value is "PHPSESSID" ;
3. session.cookie_lifetime: This represents the time the SessionID is stored in the client cookie. The default is 0, which means that the SessionID will be invalidated as soon as the browser closes it... It is because of this that the Session cannot be used permanently!
4. session.gc_maxlifetime: This is the time that Session data is stored on the server side. If this time is exceeded, the Session data will be automatically deleted!
Method 2: Set in the program, use the ini_set() function to set the session expiration time
Note: However, when the script execution ends, the setting is cleared and php will not be truly modified. ini file
session_start(); ini_set('session.gc_maxlifetime',21600);
Related recommendations:php training
The above is the detailed content of How to modify the session survival time in php. For more information, please follow other related articles on the PHP Chinese website!