Home  >  Article  >  Backend Development  >  How to redirect in PHP? A brief discussion on 3 ways to jump to a page

How to redirect in PHP? A brief discussion on 3 ways to jump to a page

青灯夜游
青灯夜游forward
2021-07-09 19:05:484492browse

Users often need to redirect the page when logging in, so how to redirect the page in PHP? The following article will introduce to you three methods of redirecting web pages to jump pages.

How to redirect in PHP? A brief discussion on 3 ways to jump to a page

The first one: Use the header() function to redirect, which is what I use more. (Note! There cannot be a space between locationhe and ":", otherwise it will have no effect!)

<?php
    header(&#39;content-type:text/html;charset=uft-8);
    //重定向页面
    header(&#39;location:index.php&#39;);
 ?>

Second: Use the meta tag in the HTML header to define http-equiv=refresh and content=”jump The time it takes to transfer (in seconds); url = jump address”

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    //跳转页面,跳转时间:3秒钟,目标地址:index.php
    <meta http-equiv="refresh" content="3;url=index.php">
    <title>skip...</title>
</head>

or

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$url=&#39;index.php&#39;;
 ?>
 <!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    //跳转页面,跳转时间:2秒钟,目标地址:index.php
    <meta http-equiv="refresh" content="2;url=<?php echo $url; ?>">
    <title>skip...</title>
</head>

The third method: use javascript to jump

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$url=&#39;index.php&#39;;
//立即跳转至目标页面
echo <script>window.location.href=&#39;$url&#39;;</script>;
?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to redirect in PHP? A brief discussion on 3 ways to jump to a page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete