有些学习者比较冲动,没心思把原理研究,所以我把它放后面. a) 服务器通过随着响应发送一个http的Set-Cookie头,在客户机中设置一个cookie(多个cookie要多个头). b) 客户端自动向服务器端发送一个http的cookie头,服务器接收读取.
HTTP/1.x 200 OK X-Powered-By: PHP/5.2.1 Set-Cookie: TestCookie=something from somewhere; path=/ Expires: Thu,19 Nov 200718:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-type: text/html
这一行实现了cookie功能,收到这行后 Set-Cookie: TestCookie=something from somewhere; path=/ 浏览器将在客户端的磁盘上创建一个cookie文件,并在里面写入:
TestCookie=something from somewhere; /
这一行就是我们用setcookie('TestCookie','something from somewhere','/');的结果.也就是用header('Set-Cookie: TestCookie=something from somewhere; path=/');的结果. <!--[endif]-->