Using cookies to achieve statistical visitor login _php Tips

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.