Modify PHP session default time method_PHP tutorial

WBOY
Release: 2016-07-13 17:14:39
Original
1079 people have browsed it

The default session validity period in PHP is 1440 seconds (24 minutes). What if we want the session to fail to expire? Let’s first introduce the best method without modifying the program, because if the program is modified , the testing department must be very depressed like me, then the only way to modify the system environment configuration is actually very simple, open the php.ini setting file,

modify the three lines as follows:

1. session.use_cookies
Set the value of this to 1 and use cookies to pass sessionid

2. session.cookie_lifetime
This represents the time that 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 PHP session cannot be used permanently! So let's set it to a number we think is big, how about 999999999, that's ok! that's all.

3. session.gc_maxlifetime
This is the time that the Session data is stored on the server side. If this time is exceeded, the Session data will be automatically deleted! Then we also set it to 99999999


If you cannot modify the php.ini file

The code is as follows
 代码如下 复制代码

session_start(); // 启动Session
$_SESSION['count']; // 注册Session变量Count
isset($PHPSESSID)?session_id($PHPSESSID):$PHPSESSID = session_id();
// 如果设置了$PHPSESSID,就将SessionID赋值为$PHPSESSID,否则生成SessionID

$_SESSION['count']++; // 变量count加1
setcookie('PHPSESSID', $PHPSESSID, time()+3156000); // 储存SessionID到Cookie中
echo $count; // 显示Session变量count的值
?>

Copy code
session_start(); // Start Session

$_SESSION['count']; // Register Session variable Count

isset($PHPSESSID)?session_id($PHPSESSID):$PHPSESSID = session_id(); $_SESSION['count']++; // Add 1 to variable count setcookie('PHPSESSID', $PHPSESSID, time()+3156000); // Store SessionID in Cookie echo $count; // Display the value of Session variable count ?>
http://www.bkjia.com/PHPjc/628957.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628957.htmlTechArticleThe default session validity period in PHP is 1440 seconds (24 minutes). What if we want the session to fail to expire? Well, let’s first introduce the best method without modifying the program, because if...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!