How to implement page redirection in php: 1. Use HTTP header information to redirect to another page; 2. Use META's REFRESH tag to implement redirection; 3. Implement redirection through scripts.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How does php implement redirection to the 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:
<? Header("Location: http://www.baidu.com"); ?>
Note that there is a space after "Localtion:".
2. Use HTML tags
Use HTML tags, that is, use REFRESH tags of META. For example:
<? 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.baidu.com"; echo "<script type="text/javascript">"; echo "location.href=’$url’"; echo "</script>"; ?>
[Recommended learning: PHP video tutorial]
The above is the detailed content of How to implement redirection in php. For more information, please follow other related articles on the PHP Chinese website!