Home > Backend Development > PHP Tutorial > PHP uses header jump failure solution

PHP uses header jump failure solution

高洛峰
Release: 2023-03-03 16:44:01
Original
1316 people have browsed it

The example in this article describes the solution to the invalid header jump in PHP and is shared with everyone for your reference. The specific method is analyzed as follows:

1. Problem:

Today’s header("Location: $url"), in the past, it was always possible to jump, but today it does not move, it just outputs the result. In the past, I had to confirm and check, $url's Is the value obtained correctly, so I added echo $url in front for debugging, but the result is that the header function is invalid.

2. Solution:

Use header("location:test.php" in PHP ) Please pay attention to the following points when jumping:

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

2. There cannot be any output before using the header, including include. There must be no space after the tag "?>" in the page.

3. The PHP code after the header will also be executed.

There cannot be any content output before the PHP header jumps, because it has already been executed when PHP starts Send HTTP header information to the browser, and then no longer allow changes.

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

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

I hope this article will be helpful to everyone’s PHP programming.



For more related articles on how to use header jump failure in PHP, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template