Summary of various methods for jumping from a PHP page to another page

高洛峰
Release: 2023-03-04 12:46:01
Original
2601 people have browsed it

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 
} 
?>
Copy after login

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>
Copy after login

3. Use scripts to implement
Examples are as follows:

<? 
$url="http://www.php.cn"; 
echo "<!--<scrīpt LANGUAGE="Javascrīpt">"; 
echo "location.href=&#39;$url&#39;"; 
echo "</scrīpt>-->"; 
?>
Copy after login

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>
Copy after login

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(\&#39;url,\&#39;\&#39;,\&#39;_self\&#39;);</script>
Copy after login


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");
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!