Home > Article > Backend Development > There are several jump methods in php
php has three jump methods, which are: 1. Use the Header function, with statements such as "Header("Location: $url");"; 2. Use META's REFRESH mark to jump; 3. Use echo to print out the script code and jump.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How many jump methods are there for php?
1. Use the Header function
For example, after the logic is established, jump to the login.php page.
<?php Header("Location: loging.php"); # URL也可以使用变量 ## Header("Location: $url"); ?>
You need to pay attention to the syntax. There is a space after Location:. You need to pay special attention to the usage: when using the Header function to jump to the page, do not put it at the top. If there is HTML in front of the statement, an error will be reported directly.
2. Using HTML tags
is actually using the REFRESH tag of META.
<? if(!isset($url)) exit;?> <HTML> <HEAD> <META HTTP-EQUIV="REFRESH" CONTENT="5; URL=<? echo $url;?>> </HEAD> <BODY> </BODY> </HTML>
First determine whether the url link exists, and if it exists, jump.
3. Using JS script
In fact, you use echo to print out the script code, and you are responsible for using the location.href API to jump.
<?php $url="http://www.baidu.com"; echo "<!--<scrīpt LANGUAGE="Javascrīpt">"; echo "location.href='$url'"; echo "</scrīpt>-->"; ?>
Use JS to complete the jump.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of There are several jump methods in php. For more information, please follow other related articles on the PHP Chinese website!