PHP header () function jump Invalid resolution

Source: Internet
Author: User
When converting the encoding, there is a page that needs to declare the UTF-8 encoding in the head, but this conflicts with a header in the program. Google a bit, find a few solutions, translation collation:

If you got the message: "Warning:cannot Modify header Information-headers already sent by ..."

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):

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 ();

3. PHP have this annoying problem, if your HTML goes before any PHP code or any headers modification before redirecting to C Ertain page, it ll said "Warning:cannot Modify header Information-headers already sent by ..." Basically anytime you output to browser, the header was set and cannot be modified. So-ways to get around the problem:

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 an out-of-cache):---I solved it in this way! It has been confirmed that can!

 
  ... HTML codes ...
 
  

Like the code above, this method caches the page when it is generated, allowing the header to be output after the head is output. The wish Board of this site is to solve the problem of the header with this method.

4.set output_buffering = on php.ini (opens output_buffering in php.ini)

Set output_buffering = On would enable output buffering for all files. But this method could slow down your PHP output. The performance of this method depends in which Web server you re working with, and what kind of the scrīpts you re using.

This method is theoretically the same as the 3b method. However, this approach opens the output cache for all PHP programs, which can affect the efficiency of PHP execution, depending on the performance of the server and the complexity of the code.

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