Home  >  Article  >  Backend Development  >  How to implement PHP page redirection

How to implement PHP page redirection

藏色散人
藏色散人Original
2018-12-01 13:35:325983browse

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.

How to implement PHP page redirection

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(&#39;Location: 填写你要重定向到的新地址&#39;);
?>

For example, in the test.php page, add the following code:

<?php
header(&#39;Location: //m.sbmmt.com/&#39;);
?>

When we access the test.php page at the front desk, we will jump to the PHP Chinese website (m.sbmmt.com)

The effect can be as follows:

How to implement PHP page redirection

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:

How to implement PHP page redirection

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!

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