Cannot modify header information-headers already sent by error Solution

Source: Internet
Author: User
Tags setcookie
<? Phpif ($ _ SESSION ["login"]! = 'Yes') {// ob_start (); // echo "<script language = javascript> alert ('Log On! '); </Script> "; // sleep (3); header (" Location: http ://". $ _ SERVER ['HTTP _ host']. "/my-login.php"); // ob_end_flush () ;}?>

Cannot modify header information-headers already sent by (output started...) is always reported ...)....

The following are some other reasons and solutions for the Cannot modify header information-headers already sent by error.

Method 1:
There are some restrictions on the use of cookies in PHP.
1. Use setcookie before the 2. You cannot use echo to input content before using setcookie.
3. The cookie will not appear until the webpage is loaded
4. setcookie is sent only when it is placed in any data output browser.
.....
Due to the above restrictions, when using the setcookie () function, you will encounter "Undefined index", "Cannot modify header information-headers already sent "... The solution is to generate a cookie before the output content. 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)
Note: When the buffer zone is activated, all non-file header information from the PHP program is not sent, but stored in the internal buffer zone. To output the buffer content, you can use ob_end_flush () or flush () to output the buffer content.


Method 2:
Solve Warning: Cannot modify header information-headers already sent ......

A few days ago, I installed a php Big Head sticker system test and found the error Warning: Cannot modify header information-headers already sent ......
This problem still occurs when openads is installed again today. Angry. After searching for the Internet for a long time, some people say they want to write ob_start () at the beginning of the file ();

Method 3:

It is found that only this method works: Open php. ini and set output_buffering to on. Restart appache, OK. It seems that this is the solution.

Note:

If you use UTF-8 encoding, be sure to remove the BOM in the UTF-8, this is because the UTF-8 encoding file contains the bom, and php4, 5 are not supported bom. Remove bom and use Notepad ++ to open the conversion. Remember, remember, remember! (This problem has plagued me for a long time .)

Use PHP's ob_start (); to control the cache URL of your browser

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.