Home >Backend Development >PHP Tutorial >Several implementation methods of PHP jump page

Several implementation methods of PHP jump page

不言
不言Original
2018-04-04 17:21:2715730browse

This article is a detailed analysis and introduction to several implementation methods of PHP jump pages. Friends who need it can refer to

Recommended Manual: php completely self-study Manual

● PHP page jump 1. header() function

The header() function is for page jump in PHP A very simple method.

The main function of the header() function is to output the HTTP protocol header (header) to the browser.

The header() function is defined as follows:

void header (string string [,bool replace [,int http_response_code]])

The optional parameter replace specifies whether to replace the previous similar header or add one of the same type header, which defaults to replacement.

The second optional parameter http_response_code forces the HTTP corresponding code to the specified value.

The Location type header in the header function is a special header call, often used to implement page jumps.

Note:
1. There cannot be a space between location and ":" , otherwise it will not jump.
2. There cannot be any output before using the header.
3.The PHP code after the header will also be executed.

For example, redirect the browser to the php Chinese website

The code is as follows:

<  ?php 
//重定向浏览器 
header("Location: https://www.php.cn/"); 
//确保重定向后,后续代码不会被执行 
exit;
?>

● PHP page jump 2. Meta tag

Meta tag is a tag in HTML that is responsible for providing document meta-information. Using this tag in a PHP program can also achieve page jumps.

If http-equiv is defined as refresh, when the page is opened, it will jump to the corresponding page within a certain period of time based on the value specified by the content.

If content="seconds;url=website" is set, it defines how long it will take for the page to jump to the specified URL.

For example, use the meta tag to automatically jump to the PHP Chinese website after one second.

The code is as follows:

<meta   http-equiv = "refresh"  content = "1;
url=https://www.php.cn/" >

For example, the following program meta.php implements the page to automatically jump to www.php.cn after staying on the page for one second.

The code is as follows:

<?php   
$ url  =  "https://www.php.cn/" ;  ?>  
<html>    
<head>    
<meta   http-equiv = "refresh"   content ="1;  
url = <?php echo $url;  ?> " >    
</head>    
<body>    
页面只停留一秒……   
</body>  
</html>

● PHP page jump three, JavaScript

For example, this code can anywhere legal in the program.

The code is as follows:

<  ?php  
$ url  =  "https://www.php.cn/" ;  
echo " <   script   language = &#39;javascript&#39;  
type = &#39;text/javascript&#39; > ";  
echo " window.location.href = &#39;$url&#39; ";  
echo " <  /script > ";  
?>
Recommended related articles:
1.Multiple methods of page jump in PHP
2.How to implement the page jump function in PHP? (Example of function tags)
Related video recommendations:
1.Dugu Jiujian(4)_PHP video tutorial

The above are the three PHP page jump implementation methods we introduced to you.

The above is the detailed content of Several implementation methods of PHP jump page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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