Reference
Http://www.cnblogs.com/panjun-Donet/articles/1250405.html
Http://www.jb51.net/article/14108.htm
Obviously, this is because of setcookie. I checked the Internet and explained the following: the cookie itself has some restrictions, for example:
1. The description of the call to setcookie must be placed before the <HTML> tag
2. You cannot use echo before calling setcookie.
3. The cookie will not appear in the program until the website is reinjected.
4. The setcookie function must be sent out before any information is sent to the browser.
5 .......
Based on the above restrictions, when setting the setcookie () function, we often encounter "undefined Index", "cannot modify header information-headers already sent "... To solve the problem, the solution "cannot modify header information-headers already sent by" is to delay the data output to the browser before the cookie is generated. Therefore, you can add ob_start (); at the beginning of the program. This will solve the problem. If you want to add ob_start (), it is not feasible. It seems a little depressing that the program has been written ..
When I found that this error was prompted, I was wondering why I didn't prompt this problem locally. I thought it was a PHP. ini configuration that was different. I thought it was similar ..
So let's look at the sentence "output started .... "It means that the output is already in another place before setcookie, so find the file following output started at and see that the first line is blank, and then <? Is PHP a problem in this line ?? I also have this line locally. Remove it, refresh it, and try again. Well, it is here, and no longer prompts warning.
Solution complete!
Solution 2:
There are many ways to solve this problem on the Internet, but today we have encountered this problem. After the test, we found it feasible:
Find the configuration file PHP. ini in Windows on drive C, and then find the item: output_buffering, change its value from the original off to on, and restart Apache.
I solved the problem by solving method 2.
<? PHP if (! Empty ($ _ cookie ['counter']) {$ counter = $ _ cookie ['counter'] + 1; echo "you are the first ". $ counter. "A visitor ". '<br>';} else {$ counter = 1;} setcookie ("counter", $ counter, time () + 2678400 ); // calculate the access traffic for one month?>