Using cookies to achieve a count of visitor landings _php Tutorial

Source: Internet
Author: User
Tags setcookie
Copy CodeThe code is as follows:
$_cookie["Counter"]? ($c =$_cookie["Counter"]+1):($c =1);
Setcookie ("Counter", $c, Time () +60);
echo " Welcome to the section ".". $c. " Second Access Cookie";
?>

In this application, the browser is the first to request a resource (this PHP page), send 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 program (index.php) has created the 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 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

http://www.bkjia.com/PHPjc/327476.html www.bkjia.com true http://www.bkjia.com/PHPjc/327476.html techarticle Copy the code as follows: PHP $_cookie["counter"]? ($c =$_cookie["Counter"]+1):($c =1); Setcookie ("Counter", $c, Time () +60); echo "B Welcome to your first." Font color= #ff0000 ". $c." /font Times visit ...

  • Related Article

    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.