Home  >  Article  >  php教程  >  PHP中设置Session过期方法

PHP中设置Session过期方法

WBOY
WBOYOriginal
2016-06-06 20:09:11933browse

Session的有效期是随浏览器进程的,浏览器关掉后就没了,那么怎么像Cookies那样设置过期时间呢?下面这段代码就可以实现。 12345 ?php$cookies_life_time = 24 * 3600; //过期时间,单位为秒,这里的设置即为一天session_start();setcookie(session_name() ,

Session的有效期是随浏览器进程的,浏览器关掉后就没了,那么怎么像Cookies那样设置过期时间呢?下面这段代码就可以实现。

 

1
2
3
4
5
<?php $cookies_life_time = 24 * 3600;   //过期时间,单位为秒,这里的设置即为一天
session_start();
setcookie(session_name() ,session_id(), time() + $cookies_life_time, "/");
?>
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