Copy Code code as follows:
<?php
$_cookie["Counter"]? ($c =$_cookie["Counter"]+1):($c =1);
Setcookie ("Counter", $c, Time () +60);
echo "<b> welcome you to the first." <font color= #ff0000 > ". $c." </font> visit cookie</b> ";
?>
In this application, first the browser requests a resource (this PHP page), sends the following HTTP header content to the server:
Get http://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 that the Dynamic Web page program (index.php) creates a cookie, the server transmits the following HTTP header content to the browser:
http/1.1 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
Get http://localhost/index.php http/1.1
---------------------------------------------------------------------------
This will save a cookie file on the client and save the $c variable
When requested again, the data in the cookie is passed to the server, such as the HTTP request header below:
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