Home  >  Article  >  Backend Development  >  What should I do if the php header jump fails? Solution

What should I do if the php header jump fails? Solution

WBOY
WBOYOriginal
2016-07-25 08:52:291269browse
Regarding the solution to the invalid php header jump, some precautions when the header jumps to the page. If you must process the header information after output, you can use ob_start() ob_end_flush() to cache the content.

Solution to invalid php header jump

1. Question: header("location: $url") fails to jump and only outputs the result. In the past, we had to confirm and check whether the value of $url was obtained correctly, so we added echo $url in front; for debugging, the result is the header function. is invalid.

2. Solution: When using header("location:test.php") to jump in PHP, please pay attention to the following points: 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, and there must be no space after the tag "?>" in the include page. 3. The php code after the header will also be executed.

No content can be output before php's header jumps, because php has already sent the http header information to the browser when it starts executing, and no changes are allowed after that. If you must process the header information after output, you can use ob_start() ob_end_flush() to cache the content and wait until the header continues before sending the content.

An easier way: Modify php.ini, find output_buffering=off and change it to: output_buffering=4096



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