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