首页  >  文章  >  后端开发  >  PHP中如何重定向网页跳转页面

PHP中如何重定向网页跳转页面

coldplay.xixi
coldplay.xixi原创
2020-09-01 13:47:272718浏览

PHP中重定向网页跳转页面的方法:1、利用【header()】函数进行重定向;2、利用HTML头部中的meta标签;3、利用javascript进行跳转。

PHP中如何重定向网页跳转页面

【相关学习推荐:php图文教程

PHP中重定向网页跳转页面的方法:

hhw:用第一种方法可以将:http://127.0.0.1/tp5  简化为http://127.0.0.1,即将www目录下的index.php文件写入第一种中的php代码:

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

 或直接:

<?php
header(&#39;content-type:text/html;charset=uft-8&#39;);
header(&#39;location:tp5/public/index.php&#39;);
?>

 

第一种:利用header()函数进行重定向,这也是我用的较多的。(注意!locationhe和“:”之间不能有空格,否则无作用!)

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

第二种:利用HTML 头部中的 meta标签,定义http-equiv=refresh 和content=”跳转花费的时间(秒为单位);url=跳转地址”

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

或者

<?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>

第三种:利用javascript进行跳转

<?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>;
?>

相关学习推荐:php编程(视频)

以上是PHP中如何重定向网页跳转页面的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn