下面是有关这个例子的代码说明,供大家参考。
以上代码中,首先,浏览器请求一个资源(这个php页面),发送下面的http包头内容到服务器:
get http://localhost/index.php http/1.1host:localhostaccept:*/*accept-language:zh-cnaccept-encoding:gzip,deflateuser-agent:mozilla/4.0 (compatible;msie 6.0;windows nt 5.1;sv1)connection:keep-alive**页程序(index.php)创建了cookie,服务器传输下面的http报头内容到浏览器:
http/1.1 200 okserver:apache/2.2.6 (win32) php/5.2.6date:fri,23 mar 2009 23:15:55 gmtconnection:keep-alivecontent-length:65content-typt:text/htmlset-cookie:visitorcount=1; expires=thr,30-jul-2010 16:00:00 gmt;domain=localhost;path=/cache-control:privateget http://localhost/index.php http/1.1这将在客户端保存一个cookie文件,并保存$c变量,当再次请求时,就会将cookie中的数据传给服务器,例如下边的http请求报头:
accept:*/*accept-language:zh-cnpragma:no-cacheuser-agent:mozilla/4.0(compatible;msie 6.0;windows nt 5.1; sv1)host:localhostconnection:keep-alivecookie:visitorcount=1有了这样的分析,希望有助于大家理解与掌握php中cookie的用法。