Home  >  Article  >  Backend Development  >  Detailed explanation of setting session survival time in php_PHP tutorial

Detailed explanation of setting session survival time in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:50:24930browse

To set the php survival time, we can use the session_set_cookie_params function or modify the php.ini file. Let me introduce it below.

The first method: 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;    //一个小时

session_set_cookie_params($lifetime);

session_start();

Copy code

 代码如下 复制代码


session_start();
// 保存一天
$lifeTime = 24 * 3600;
setcookie(session_name(), session_id(), time() + $lifeTime, “/”);
?>

$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; ?> Second method: If you have the permission to operate the server, then setting this up is very, very simple. You just need to follow the following steps:
1. Set "session.use_cookies" to 1 and turn on Cookie to store SessionID, but the default is 1 and generally does not need to be modified; 2. Change "session.cookie_lifetime" to positive infinity (of course there is no parameter for positive infinity, 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
http://www.bkjia.com/PHPjc/632658.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632658.htmlTechArticleTo set the php survival time, we can use the session_set_cookie_params function or modify the php.ini file. The editor will introduce it below. one time. The first method: session_set_cookie_params...
Statement:
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