PHP中重定向網頁跳轉頁面的方法(共三種)
大家好,我是Yangrl
今天在做用戶登錄功能時用到了重定向頁面,之後比較感興趣,學習總結了三種方法,加深記憶。
第一種:利用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中重定向頁面的三種方法。
“羅素:參差多態纔是幸福本源”——《沉默的大多數》