Home > Article > Backend Development > How to implement PHP page redirection
The so-called PHP page redirection is to redirect one PHP page to another page, that is, to redirect the user to other pages. The most common and simple method is to use the header function.
So how do we implement it? It's actually very simple.
If you want to redirect a page to another page, you can add the following code directly to the header of the page:
<?php header('Location: 填写你要重定向到的新地址'); ?>
For example, in the test.php page, add the following code:
<?php header('Location: http://www.php.cn/'); ?>
When we access the test.php page at the front desk, we will jump to the PHP Chinese website (www.php.cn)
The effect can be as follows:
header function syntax:
void header(string $ header [,bool $ replace = TRUE [,int $ http_response_code]])
header() is used to send the original HTTP header.
The parameters respectively represent:
header: title string.
replace: The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type.
http_response_code: Force the HTTP response code to the specified value. Note that this parameter only works if the header is not empty.
The flow chart is as follows:
This article is a brief introduction to the implementation of page redirection in PHP. I hope it will be helpful to friends in need!
The above is the detailed content of How to implement PHP page redirection. For more information, please follow other related articles on the PHP Chinese website!