PHP uses the header to redirect to an invalid solution

Source: Internet
Author: User
This article mainly introduces how PHP uses the header to jump to an invalid solution, and summarizes the precautions for such problems, which is of great practical value, for more information about how PHP uses the header to redirect to invalid content, see the example in this article. The specific method is analyzed as follows:

I. problems:

Today's header (\ "Location: $ url \"), the previous jump is always possible, but today it does not move, only the output results, in the past you have to confirm the check, the $ url value is obtained correctly. Therefore, echo $ url is added in front of the url for debugging. as a result, the header function is invalid.

II. solution:

When using header ("location: test. PHP") in php to redirect, pay attention to the following points:

1. no space is allowed between location and:; otherwise, an error occurs. // phpfensi.com

2. there cannot be any output before using the header, including the "?>" tag on the include page" There cannot be spaces.

3. the PHP code after the header is executed.

No content can be output before the PHP header jump, because the HTTP header information has been sent to the browser at the beginning of PHP execution and cannot be changed.

However, if you have to process the header information after the output, you can use ob_start () ob_end_flush () to cache the content to be sent and wait until the header continues to send the content.

Or a simpler method is to modify php. ini and find output_buffering = Off and change it to output_buffering = 4096.

I hope this article will help you with PHP programming.

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.