Ask a newbie a question (only a few lines of code)

Source: Internet
Author: User
Ask a newbie (only a few lines of code) & lt ;? Php $ count = $ _ COOKIE [nam]; $ count ++; setcookie (& quot; nam & quot;, $ count, time () + 30 ask a newbie question (only a few lines of code)
$ Count = $ _ COOKIE [nam];
$ Count ++;
Setcookie ("nam", $ count, time () + 300 );
Echo "Welcome!
You are the $ count guest ";
?>
Why can this code record the number of visitors? Isn't the cookie stored on the visitor's computer? Isn't this the only way to record the number of visits to the browser?

------ Solution --------------------
Discussion
$ Count = $ _ COOKIE [nam];
$ Count ++;
Setcookie ("nam", $ count, time () + 300 );
Echo "Welcome!
You are the $ count guest ";
?>
Why can this code record the number of visitors? Isn't the cookie stored on the visitor's computer? Isn't this the only way to record the number of visits to the browser?

------ Solution --------------------
Discussion
$ _ COOKIE is stored on the client. However, when an http request is sent, the browser sends the Cookie corresponding to the website to the server.
This is the value of the $ _ COOKIE Super variable in php.
If you want to set a new value, the server sends an http header through setcookie () to set

------ Solution --------------------
Discussion
$ Count = $ _ COOKIE [nam];
$ Count ++;
Setcookie ("nam", $ count, time () + 300 );
Echo "Welcome!
You are the $ count guest ";
?>
Why can this code record the number of visitors? Isn't the cookie stored on the visitor's computer? Isn't this the only way to record the number of visits to the browser?

------ Solution --------------------
This is just an example. Not true

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.