This error was encountered today when testing the following code:
Copy Code code as follows:
Session_Start ();
$_session[' username ']= $username;
echo "<script language= ' JavaScript ' >location.href=". /admin.php ';</script> ';
Exit ();
Error occurred:
Copy Code code as follows:
Warning:cannot Modify header Information-headers already sent by ...
Read some online methods also did not solve, finally in the php.ini configuration output_buffering defaults to 4096 did not encounter this error:
Output_buffering Setting Description:
Off: means to turn off the PHP output cache
On: Open an infinitely large output cache
4096: Open output Cache size 4096Byte
By default, PHP buffer is turned on, and the buffer default is 4096, or 4KB. You can find the output_buffering configuration in the php.ini configuration file. When Echo,print output user data, the output data will be written to the PHP output_buffering until Output_ The buffering is full, sending the data over TCP to the browser display. You can also manually activate the PHP output_buffering mechanism by Ob_start (), so that even if the output exceeds 4KB data, it does not really send the data to TCP to the browser, because Ob_start () the PHP buffer space set to large enough. The data is sent to the client browser only until the end of the script, or when the Ob_end_flush function is invoked.
About Output_buffering Detailed introduction can refer to:
Http://www.jb51.net/article/55707.htm
Add: Of course, you can also remove the BOM to solve this problem, it is recommended to UTF-8 no BOM format coding. Thank @ihipop Children's shoes
On the BOM, in simple terms, the software through the BOM to identify whether the file is UTF-8 code. In the early versions of Firefox, the extensions were not BOM, but the Firefox 1.5 version has already started supporting the BOM. It is now found that PHP does not support BOM. PHP does not consider the issue of the BOM at design time, that is, he will not ignore the three characters of the BOM at the beginning of the UTF-8 encoded file.
One of the other problems mentioned was that "the cookie-delivery mechanism limits the cookie from being sent out in a file with a BOM at the beginning of the file (because PHP sent the file header before the cookie was sent out), so the login and logout function failed." All the functionality that relies on cookies and session implementations is invalid. "This should be the reason for a blank page in the WordPress background, because any one of the executed files contains a BOM, these three characters will be sent out, resulting in the function of cookies and session failure, so you may also encounter the following error:
Copy Code code as follows:
Warning:session_start () [Function.session-start]: Cannot send session cookie-headers already sent by (output started at e:\web\index.php:1) in E:\web\functions\sessions.php on line 39