PHP completely eradicated warning:cannot add header information-headers already sent in.

Source: Internet
Author: User
PHP completely eliminate Warning:cannot add header information-headers already sent in ...

Solution:

1) For those who have permission to edit php.ini

Open the php.ini file (you are better than I know where your php.ini is) and find

output_buffering = change to On or any number. If it is IIS6, please change to ON, otherwise your PHP efficiency will be very slow.

2) Use virtual host, can't edit php.ini, how to do?

Simple:

Create a. htaccess file in your spatial root directory with the following content:

AllowOverride All
Php_flag output_buffering on

The unfortunate situation is: or not? All pages are not displayed?

Well, you can call and scold a space quotient, and then let him give you the Apache. htaccess allowoverride Open

3) Resolve in PHP file

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

Ob_end_flush ()
Send output buffer (out buffering) and disable the output buffering mechanism.

Ob_end_clean ()
Clears output buffer but does not send, and disables output buffering.

Ob_get_contents ()
Returns the current output buffer as a string. Allows you to handle any output that the script emits.

Principle:

When Output_buffering is enabled, PHP does not send an HTTP header when the script sends the output. Instead, it imports this output through a pipeline (pipe) into a dynamically increasing cache (only used in PHP 4.0, which has a centralized output mechanism). you can still modify/add a header, or set a cookie because the header is not actually sent . When all the scripts are terminated, PHP automatically sends the HTTP header to the browser, and then sends the contents of the output buffer.

Reprint please must indicate from: 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.