Php thoroughly rooted warning: Cannotaddheaderinformation-headersalreadysentin.

Source: Internet
Author: User
Php completely eliminates warning: Cannotaddheaderinformation-headersalreadysentin ...... solution: 1) applicable to PHP with permission to edit. INI people open php. ini file (you should be clear about your php. ini), change output_buffering to on or any number. if it is II php, completely eliminate warning: Cannot add header information-headers already sent in ......

Solution:

1) applicable to persons with permissions to edit PHP. INI

Open the php. ini file (you should know where your php. ini is) and find

Output_buffering = changed to on or any number. if it is IIS6, change it to ON. Otherwise, your PHP efficiency will be very slow.

2) when using a VM, you cannot edit PHP. INI. what should I do?

Simple:

Create a. htaccess file under the root directory of your space. the content is as follows:

AllowOverride All
PHP_FLAG output_buffering On

Unfortunately: or not? Cannot all webpages be displayed?

Then, you can call a space provider and ask him to open apache. htaccess AllowOverride.

3) solve the problem in the PHP file

Ob_start ()
Enable the output buffering mechanism. Output buffering supports multiple levels-for example, you can call the ob_start () function multiple times.

Ob_end_flush ()
Sends the output buffer and disables the output buffering mechanism.

Ob_end_clean ()
Clear the output buffer but not send it, and disable output buffering.

Ob_get_contents ()
Returns the current output buffer as a string. Allows you to process any output from the script.

Principle:

When output_buffering is enabled, PHP does not send HTTP headers when the script sends the output. Instead, it inputs this output to the dynamically added cache through the pipeline (pipe) (which can only be used in PHP 4.0 and has a centralized output mechanism ). You can still modify/add the header or set the cookie because the header is not actually sent. When all scripts are terminated, PHP automatically sends the HTTP header to the browser, and then sends the content in the output buffer.

For reprinting, please note that the source is www.phpv.net.

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.