下面是别人建议
Method 1:
There are some restrictions on the use of cookies in PHP.
1. Use setcookie must be before the tag
2. Before using setcookie, you cannot use echo to input content
3. The cookie will not appear until the web page is loaded
4. Setcookie must be placed before any data is output to the browser before it is sent
... ..
Due to the above restrictions, when using the setcookie() function, you may encounter problems such as "Undefined index", "Cannot modify header information - headers already sent by"..., the solution is Before outputting content, a cookie is generated. You can add the function ob_start() at the top of the program;
ob_start: open the output buffer
Function format: void ob_start(void)
Explanation: When the buffer is activated, all non-file header information from the PHP program will not be sent, but will be saved in the internal buffer. In order to output the contents of the buffer, you can use ob_end_flush() or flush() to output the contents of the buffer.
Method 2:
Solution to Warning: Cannot modify header information - headers already sent by ..... . A few days ago, I installed a php photo sticker system to test, and found that the error message Warning: Cannot modify header information - headers already sent by ......
I installed openads again today, and this error still occurred. question. Angry.After searching online for a long time, someone said to write
ob_start();
at the beginning of the file but failed.
Later open php.ini and set output_buffering to on. Restart appache, OK. It seems this is the solution.
Special note: (I solved the problem just after reading this)
If you use utf -8 encoding, you must remove the BOM in UTF-8. This is because the UTF-8 encoded file contains BOM, and php4 and 5 do not support BOM. To remove the BOM, you can open it with Notepad++ and convert it. (I solved the problem after reading this)
Solution by yourself
PHP4 and 5 do not support BOM in utf-8 encoded files