Example code for calculating the number of visitors logging in using cookies in php
- $ _ COOKIE ["counter"]? ($ C = $ _ COOKIE ["counter"] + 1) :( $ c = 1 );
- SetCookie ("counter", $ c, time () + 60 );
- Echo"Welcome to the cookie "." ". $ c ."";
- // By bbs.it-home.org
- ?>
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: privateGET 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 = 1With this analysis, we hope to help you understand and understand the usage of cookies in php. |