Solution of Jump Failure in PHP Using header

  • 2021-07-22 09:15:23
  • OfStack

This article describes the example of PHP using header jump failure solution, to share for your reference. Specific methods are analyzed as follows:

1. Issues:

Today header (\ "Location: $url\"), in the past, jumping was always possible, but today it doesn't move, just output the result. In the past, I had to confirm and check whether the value of $url was obtained correctly, so echo $url was added in front; For debugging, the result is that the header function is invalid.

2. Solution:

The following points should be noted when jumping with header ("location: test. php") in PHP:

1. There must be no space between location and ":", otherwise an error will occur.//phpfensi. com

2. You can't have any output before using header, including the label in the page of include. "? > There can be no spaces after ".

3. PHP code after header will also be executed.

No content can be output before the header jump of PHP, because the HTTP header is sent to the browser when PHP starts execution, and no changes are allowed after that.

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

Or a simpler way, modify php.ini, find output_buffering=Off and modify it to output_buffering=4096.

I hope this article is helpful to everyone's PHP programming.


Related articles: