PHP cannot modify header informationheaders already sent by solution _php Tutorial

Source: Internet
Author: User
If you see this warning when you execute a PHP program: "Warning:cannot Modify header Information-headers already sent by ..."

Few notes based on the following user posts:
The following workarounds are available:

1. Blank lines (empty line):
Make sure no blank line after of the calling PHP scrīpt.
Check that there are no blank lines behind, especially the include or require files. Many problems are caused by these blank lines.

2. Use Exit statement (to be resolved with exit):
Use exit after header statement seems to help some people
Add exit () after the header;
Header ("location:xxx");
Exit ();

3a. Use JAVASCRĪPT (to be resolved with javascrīpt):
Self.location (file.php); >
Since It s a scrīpt, it won T modify the header until execution of JAVASCRĪPT.
You can use JAVASCRĪPT instead of headers. It is also important to note that using this approach requires a browser to support JAVASCRĪPT.

3b. Use output buffering (to be resolved with the export cache):

... HTML codes ...
... PHP codes ...
Header ("Location: ....");
Ob_end_flush ();
?>

Another article

Ob_start ();
Setcookie ("username", "Song Yan 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 reason
I added the header to the PHP program,

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

After the page appears above the error, read n data also has no results. Today occasionally found that the original is my php.ini inside the configuration out of the problem, found in c:windows php.ini file
The output_buffering default is off.

Tips, there is a better solution is to php.ini and then set output_buffering to On [...] There would be no such problem.

http://www.bkjia.com/PHPjc/632112.html www.bkjia.com true http://www.bkjia.com/PHPjc/632112.html techarticle If you see this warning when you execute a PHP program: Warning:cannot Modify header information-headers already sent by .... Few notes based on the following user posts: There are several solutions ...

  • 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.