刚才有同学在群里询问:$_COOKIE 的时间是多长,他指的是“我直接用 $_COOKIE存取的”,也就是说用$_COOKIE这个全局变量保存一个值。那么这个值会存在多长时间,而不是用setcookie来指定。
那么这个值到底是保存多长时间呢?在PHP手册上面查询,没有找到结果,最后发现是在php.ini里指定的。
1
2
3
4
5
6
7
8
9
10
11
12
; 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的话那么就和浏览器进程是相同的。
1
2
3
4
5
<?php
$coo = 'xxx';
$_COOKIE['xxx'] = $coo;
var_dump($_COOKIE);
?>
结果为 array(2) { [“ZDEDebuggerPresent”]=> string(14) “php,phtml,php3″ [“xxx”]=> string(3) “xxx” }
而如果我把代码改为如下内容
1
2
3
<?php
var_dump($_COOKIE);
?>
刷新浏览器,结果为:array(1) { [“ZDEDebuggerPresent”]=> string(14) “php,phtml,php3″ }
$_COOKIE默认的值由php.ini中的session.cookie_lifetime指定。
文章分类
标签云
Gray,
Public,
灰度发布,
灰度放量,
ABTest,
AB测试,
分流发布
CentOS,
Linux,
Shell
Mac,
Shell,
Vim
Linux
SSH
Mac
Mail
MacOSX
命令
MySQL,
调优
Apache,
HTTP,
ngnix
MySQL
gif,
jpeg,
png
Markdown
CentOS
PHP,
WordPress,
Blog
AsciiDoc,
mod_deflat
sudo
Leopard,
Snow
Leopard
Apache
Nginx,
木马
hostname,
upload
md5,
md5sum,
DNS
版本
Cookie,
PHP
Chrome
DooPHP,
CSS
Filter
IT
Java,
Maven,
Thrift
Git
Memcache
MongoDB
Node
Node.js
npm
HTML
Nginx
JDK,
Sublime
Timestamp
Lua,
Redis,
MacOSX,
Class,
Function
Sublime,
Snippets
ObjC
Cobar,
Bash
Brew,
Homebrew
AsciiDoc
Error
Yii
MacOSX,Hadoop,MapReduce
memcache,
Markdown,
Jekyll
VIM
Go,
Golang,
Redis
MacTeX,
CJK,
Tex
Tex,
LaTex
R,
Brew
Android,
Java
EC
Mou
GoAgentX,
GoAgent
Python
HBase
Markdown,Slide
Jenv
kerberos
Junit
Maven
虚拟化
LXC
Docker
bridge
AngularJS
PHPUnit
Android
composer
Golang
ReactNative,
项目管理
MAMP,
Memcache,
SecureCRT,
Zoc,
Mail,
GPG
Docker,
Supervisor
Test
Retail
Pay