码迷,mamicode.com
首页 > Web开发 > 详细

PHP中重定向网页跳转页面的方法(共三种)

时间:2020-04-04 20:21:05      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:java   方法   doctype   uft   声明   index   lang   ext   art   

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

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

 或直接:

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

 

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

<?php
header(‘content-type:text/html;charset=uft-8);
//重定向页面
header(‘location:index.php‘);
?>
第二种:利用HTML 头部中的 meta标签,定义http-equiv=refresh 和content=”跳转花费的时间(秒为单位);url=跳转地址”

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

或者

<?php
header(‘content-type:text/html;charset=utf-8‘);
$url=‘index.php‘;
?>
<!DOCTYPE html>
<html lang="en">
<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(‘content-type:text/html;charset=utf-8‘);
$url=‘index.php‘;
//立即跳转至目标页面
echo <script>window.location.href=‘$url‘;</script>;
?>

以上就是PHP中重定向页面的三种方法。
————————————————
版权声明:本文为CSDN博主「yAngrUiLin啊」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yaruli/java/article/details/78837240

PHP中重定向网页跳转页面的方法(共三种)

标签:java   方法   doctype   uft   声明   index   lang   ext   art   

原文地址:https://www.cnblogs.com/huhewei/p/12633701.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!