Summary of common page jump methods of php

  • 2020-05-30 19:21:07
  • OfStack

In the php writing sometimes the user page jump, here is a collection of a few good jump methods, you can use.

Implemented with HTTP header information

So PHP, HEADER. The HEADER function in PHP sends the browser control instructions specified by the HTTP protocol that should have been sent through the WEB server, such as the type of information to be returned (" Context-type: xxx/xxx"), the properties of the page ("No cache", "Expire"), and so on.
The way to redirect to another page with the HTTP header information is as follows:


<?
if (isset($url))
{
Header("HTTP/1.1 303 See Other");
Header("Location: $url");
exit; //
}
?>

Use HTML tag

To use HTML is to use REFRESH of META, for example:


<? if (!isset($url)) exit;?>
<HTML>
<HEAD>
<META HTTP-EQUIV="REFRESH" CONTENT="5; URL=<? echo $url;?>>
</HEAD>
<BODY>
</BODY>
</HTML>

Implement it in a script


<?
$url="https://www.ofstack.com";
echo "<!--<scr and pt LANGUAGE="Javascr and pt">";
echo "location.href='$url'";
echo "</scr and pt>-->";
?>

Take advantage of html features


echo "< meta http-equiv=\\"Refresh\\" content=\\" Number of seconds ; url= The file or address to jump to \\" > ";

Where :XX is the number of seconds,0 is the immediate jump.refresh means refresh.Url is the page to jump to.

Implement with script


echo '<script>url="submit.php";window.location.href=url;</script>';

The other is implemented using script

With the implementation of script, the difference is the use of open statement, and you can limit whether the original window is a parent window, a child window or a new window.


<script>url="submit.php";window.open(\'url,\'\',\'_self\');</script>

Among them, change \'_self\' to realize jump restriction on whether the original window is a parent window, a child window or a new window


header("Location: Url");

Fastest, powerful... However, one problem must be pointed out: if you have html output before using this function, even if it is 1 space, the error message will be displayed at the top of the page.

That's all for this article, I hope you enjoy it.


Related articles: