Home  >  Article  >  Backend Development  >  Do you know how to redirect web pages in PHP? Let’s talk about it together

Do you know how to redirect web pages in PHP? Let’s talk about it together

慕斯
慕斯forward
2021-06-01 09:57:402577browse

today's This article will continue to lead you to learn how to redirect web pages in PHP. I believe you will gain a lot after reading this article. Without further ado, let me take a look!

Do you know how to redirect web pages in PHP? Let’s talk about it together

##How to redirect web pages in PHP ( Three types in total)

Today I used the redirect page when doing the user login function. I became more interested in it later and learned and summarized the three methods to deepen my memory.

The first one: Use the header() function for redirection, which is what I use most. (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 way: 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>;
?>

The above is PHP Three ways to redirect pages in .

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of Do you know how to redirect web pages in PHP? Let’s talk about it together. 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