Home > Backend Development > PHP Problem > How to modify the session survival time in php

How to modify the session survival time in php

王林
Release: 2023-03-07 11:00:02
Original
3440 people have browsed it

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.

How to modify the session survival time in php

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template