PHP cannot modify header information-headers already sent_php tutorial

Source: Internet
Author: User
This article describes a variety of PHP cannot modify header information-headers already sent by set solution, there is a need for some friends can refer to.

Set output_buffering to on in PHP config file php.ini. Open.

Output_buffering = On

-------------------------------
All or nothing, now or never.


The following workarounds are available:

1. Blank lines (empty line):
Make sure no blank line after the calling PHP script.
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):

The code is as follows Copy Code
Use exit after header statement seems to help some people
Add exit () after the header;
Header ("location:xxx");
Exit ();

Use JavaScript (to solve with JavaScript):

The code is as follows Copy Code

Since it ' s a script, it won ' t modify the header until execution of Javascript.
You can use JavaScript instead of headers. But the above code I did not execute success ... It is also important to note that this approach requires JavaScript to be supported by the browser.

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

The code is as follows Copy Code

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

http://www.bkjia.com/PHPjc/632237.html www.bkjia.com true http://www.bkjia.com/PHPjc/632237.html techarticle This article describes a variety of PHP cannot modify header information-headers already sent by set solution, there is a need for some friends can refer to. In PHP config file php.ini ...

  • Related Article

    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.