$_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 =

php.ini里面可以设置session.cookie_lifetime这个值,即默认cookie保存多少秒,如果为0的话那么就和浏览器进程是相同的。

$coo = 'xxx';

$_COOKIE['xxx'] = $coo;

var_dump($_COOKIE);
?>

结果为 array(2) { ["ZDEDebuggerPresent"]=> string(14) “php,phtml,php3″ ["xxx"]=> string(3) “xxx” }

而如果我把代码改为如下内容

var_dump($_COOKIE);
?>

刷新浏览器,结果为:array(1) { ["ZDEDebuggerPresent"]=> string(14) “php,phtml,php3″ }

$_COOKIE默认的值由php.ini中的session.cookie_lifetime指定。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值