Php Cannot modify header informationheaders already sent by solution

Source: Internet
Author: User

If you see this Warning when executing the php program: "Warning: Cannot modify header information-headers already sent ...."

Few notes based on the following user posts:
There are several solutions:

1. Blank lines (Blank line ):
Make sure no blank line after <? Php...?> Of the calling php scr limit pt.
Check whether <? Php...?> There are no blank lines, especially include or require files. Many problems are caused by these blank rows.

2. Use exit statement (Use exit to solve ):
Use exit after header statement seems to help some people
Add exit () after the header ();
Header ("Location: xxx ");
Exit ();

3a. Use limit Cr limit pt (solve with limit Cr limit pt ):
<? Echo "<scr platinum pt> self. location (file. php); </scr platinum pt>";?>
Since it s a scr limit pt, it won t modify the header until execution of your Cr limit pt.
You can replace the header with Javascr into pt. In addition, it should be noted that the browser needs to support Javascr into pt.

3b. Use output buffering (solved by the output cache ):
<? Php ob_start ();?>
... HTML codes...
<? Php
... PHP codes...
Header ("Location :....");
Ob_end_flush ();
?>

Another article

<? Php
Ob_start ();
Setcookie ("username", "bin", time () + 3600 );
Echo "the username is:". $ HTTP_COOKIE_VARS ["username"]. "n ";
Echo "the username is:". $ _ COOKIE ["username"]. "n ";
Print_r ($ _ COOKIE );
?>
Warning: Cannot modify header information-headers already sent by error cause
I added the header of the php program,

Header ("cache-control: no-cache, must-revalidate ");

The above error is displayed on the page, and N documents are not returned. Today, I occasionally found a problem with the configuration in my php. ini, and found the php. ini file in C: windows.
Output_buffering is off by default.

Tips: Another better solution is to set output_buffering to on [...] in php. ini.

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.