2009十一月26
$_COOKIE 默认保存时间
刚才有同学在群里询问:$_COOKIE 的时间是多长,他指的是“我直接用 $_COOKIE存取的”,也就是说用$_COOKIE这个全局变量保存一个值。那么这个值会存在多长时间,而不是用setcookie来指定。
那么这个值到底是保存多长时间呢?在PHP手册上面查询,没有找到结果,最后发现是在php.ini里指定的。
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0
; The path for which the cookie is valid.
session.cookie_path = /
; The domain for which the cookie is valid.
session.cookie_domain =
; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript.
session.cookie_httponly =
session.cookie_lifetime = 0
; The path for which the cookie is valid.
session.cookie_path = /
; The domain for which the cookie is valid.
session.cookie_domain =
; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript.
session.cookie_httponly =
php.ini里面可以设置session.cookie_lifetime这个值,即默认cookie保存多少秒,如果为0的话那么就和浏览器进程是相同的。
<?php
$coo = 'xxx';
$_COOKIE['xxx'] = $coo;
var_dump($_COOKIE);
?>
$coo = 'xxx';
$_COOKIE['xxx'] = $coo;
var_dump($_COOKIE);
?>
结果为 array(2) { ["ZDEDebuggerPresent"]=> string(14) “php,phtml,php3″ ["xxx"]=> string(3) “xxx” }
而如果我把代码改为如下内容
<?php
var_dump($_COOKIE);
?>
var_dump($_COOKIE);
?>
刷新浏览器,结果为:array(1) { ["ZDEDebuggerPresent"]=> string(14) “php,phtml,php3″ }
$_COOKIE默认的值由php.ini中的session.cookie_lifetime指定。
文章作者:simaopig
本文地址:http://www.xiaoxiaozi.com/2009/11/26/1651/
版权所有 © 转载时必须以链接形式注明作者和原始出处!
;-) 很好,正找呢
[回复]
@网络生活
呃。。刚才给同学查完后就写下来了。呵呵。 :razz:
[回复]
我到现在也没正在明白COOKIE到底是啥意思,,,只知道是历史记录~~~
[回复]
@洗眼器
其实就是服务端生成,保存在用户本地,以证明用户身份的一种数据。
[回复]
每项保存的时间不同吧,就像论坛可以选择1天或者永久,用CCleaner清理一遍没了 :grin:
[回复]
@LAONB
不是我要清理,是想知道默认用$_COOKIE全局设置cookie的时候会保存多长时间。
真正我写的时候一般用setcookie自己指定时间的。嗯。
[回复]
@simaopig
高级问题我就搞不定了
[回复]