Example code for calculating the number of visitors logging in using cookies in php

Source: Internet
Author: User
Example code for calculating the number of visitors logging in using cookies in php

  1. $ _ COOKIE ["counter"]? ($ C = $ _ COOKIE ["counter"] + 1) :( $ c = 1 );
  2. SetCookie ("counter", $ c, time () + 60 );
  3. Echo"Welcome to the cookie "." ". $ c ."";
  4. // By bbs.it-home.org
  5. ?>

The following code describes the example for your reference.

In the above code, first, the browser requests a resource (this php page) and sends the following HTTP header content to the server:

GET http: // localhost/index. php HTTP/1.1 HOST: localhostAccept: */* Accept-language: zh-cnAccept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) Connection: Keep-Alive

** The page program (index. php) creates a Cookie. the server transmits the following HTTP header content to the browser:

HTTP/1.1 200 OKServer: Apache/2.2.6 (Win32) PHP/5.2.6Date: Fri, 23 Mar 2009 23:15:55 GMTConnection: Keep-AliveContent-Length: 65Content-Typt: text/htmlSet-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 the request is made again, the data in the cookie will be sent to the server, for example, the following HTTP request header:

Accept: */* Accept-language: zh-cnPragma: no-cacheUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) Host: localhostConnection: keep-AliveCookie: VisitorCount = 1

With this analysis, we hope to help you understand and understand the usage of cookies in php.

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.