PHP cookie和session的分析
1. PHP的COOKIE cookie 是一种在远程浏览器端储存数据并以此来跟踪和识别用户的机制。 PHP在http协议的头信息里发送cookie, 因此 setcookie() 函数必须在其它信息被输出到浏览器前调用,这和对 header() 函数的限制类似。 1.1 设置cookie: 可以用 setcookie() 或 setrawcookie() 函数来设置 cookie。也可以通过向客户端直接发送http头来设置. 1.1.1 使用setcookie()函数设置cookie: bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure [, bool httponly]]]]]] ) name: cookie变量名 value: cookie变量的值 expire: 有效期结束的时间, path: 有效目录, domain: 有效域名,顶级域唯一 secure: 如果值为1,则cookie只能在https连接上有效,如果为默认值0,则http和https都可以. 例子: <?php $value = ’something from somewhere’; setcookie(”TestCookie”, $value);