Copy codeThe Code is as follows:
<? Php
$ _ COOKIE ["counter"]? ($ C = $ _ COOKIE ["counter"] + 1) :( $ c = 1 );
SetCookie ("counter", $ c, time () + 60 );
Echo "<B> welcome". "<font color = # ff0000>". $ c. "</font> cookie </B> ";
?>
In this application, the browser requests a resource (this php page) and sends the following HTTP header content to the server:
Gethttp: // localhost/index. php http/1.1
HOST: localhost
Accept :*/*
Accept-language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Connection: Keep-Alive
---------------------------------------------------------------------------
Now the dynamic web page program (index. php) creates a Cookie, the server will transmit the following HTTP header content to the browser:
HTTP/1.1 200 OK
Server: Apache/2.2.6 (Win32) PHP/5.2.6
Date: Fri, 23 Mar 2009 23:15:55 GMT
Connection: Keep-Alive
Content-Length: 65
Content-Typt: text/html
Set-Cookie: VisitorCount = 1; expires = Thr, 30-Jul-2010 16:00:00 GMT; domain = localhost; path =/
Cache-control: private
Gethttp: // localhost/index. php http/1.1
---------------------------------------------------------------------------
This will save a cookie file on the client and save the $ c variable
When a request is sent again, the data in the cookie is sent to the server, for example, the following HTTP Request Header:
Accept :*/*
Accept-language: zh-cn
Pragma: no-cache
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Host: localhost
Connection: Keep-Alive
Cookie: VisitorCount = 1