PHP实现页面跳转方法

  本文介绍PHP实现页面跳转的三种方法,分别是PHP提供的header()函数、html的meta标签和JavaScript脚本,下面分别介绍这三种方法的具体实现方式。

PHP的head()函数

1
2
3
4
5
<?php 
header("Location: http://www.baidu.com");
//后续代码不会被执行
exit;
?>

JavaScript脚本

1
2
3
4
5
6
<?php  
$url = "http://www.baidu.com" ;
echo"<script language = 'javascript' type = 'text/javascript'>";
echo" window.location.href = '$url'";
echo" </script>";
?>

html的meta标签

1
2
3
4
5
6
7
8
9
10
11
12
<?php   
$url = "http://www.baidu.com";
?>
<html>
<head>
<meta http-equiv = "refresh" content ="0.00.1;
url = <?php echo $url;?>">
</head>
<body>
页面只停留一秒……
</body >
</html >

测试html代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html>
<body>
<form action="http://127.0.0.1/1.php">
用户名:<br>
<input type="text" name="Username" value="admin">
<br> 密码:<br>
<input type="text" name="Password" value="123456">
<br><br>
<input type="submit" value="确定">
</form>
<p>点击确定,表单数据将发送到text.php页面,然后该页面自动跳转至百度首页</p>
</body>
</html>