Home > Article > Backend Development > Summary of various methods for jumping from a PHP page to another page
1. Use HTTP header information
That is, use PHP’s HEADER function. The function of the HEADER function in PHP is to issue control instructions to the browser that should be passed through the WEB server specified by the HTTP protocol, such as declaring the type of return information ("Context-type: xxx/xxx"), the attributes of the page ("No cache", "Expire"), etc.
The method of redirecting to another page using HTTP header information is as follows:
<? if (isset($url)) { Header("HTTP/1.1 303 See Other"); Header("Location: $url"); exit; //from www.w3sky.com } ?>
Note that there is a space after "Localtion:".
2. Use HTML tags
Use HTML tags, that is, use META’s REFRESH tag. Examples are as follows:
<? if (!isset($url)) exit;?> <HTML> <HEAD> <META HTTP-EQUIV="REFRESH" CONTENT="5; URL=<? echo $url;?>> </HEAD> <BODY> </BODY> </HTML>
3. Use scripts to implement
Examples are as follows:
<? $url="http://www.php.cn"; echo "<!--<scrīpt LANGUAGE="Javascrīpt">"; echo "location.href='$url'"; echo "</scrīpt>-->"; ?>
The following is a supplement
The fourth method:
echo "< meta http-equiv=\\"Refresh\\" content=\\"number of seconds; url=jumped file or address\\" > ; ";
Where: XX is the number of seconds, 0 is an immediate jump. refresh means refresh. Url is the page to jump to.
The fifth way: use script to achieve
<script>url="submit.php";window.location.href=url;</script>
Sixth: Use script to implement, the difference is to use the open statement. And you can limit the original window to the parent window, child window or new window.
<script>url="submit.php";window.open(\'url,\'\',\'_self\');</script>
Among them, changing \'_self\' can realize the jump restriction of the original window, parent window, child window or new window. The seventh method: use php's own function to send header information
header("Location: Url");
Speed Fastest, powerful... But there is a problem that must be pointed out: if there is already html output before using this function, even if it is a space, then an error message will be displayed at the top of the page..
For more PHP pages to jump to another page, various methods and methods to summarize related articles, please pay attention to the PHP Chinese website!