1. 程式人生 > >PHP中頁面的跳轉

PHP中頁面的跳轉

一、

header()函式

語法:

void header (string string [,bool replace [,int http_response_code]])

舉個例子吧:

1、跳轉到本地的一個deom.html(立刻跳轉,沒有任何延遲)

<?php
header("content-type:text/html;charset=utf-8");
header('location:deom.html');

2、跳轉到本地的一個deom.html(可以設定延遲時間)

<?php
header("content-type:text/html;charset=utf-8");
header('refresh:10;url=deom.html');

優點:指令簡單

缺點:在使用header()函式進行輸出時,前面不可以有任何輸出(空行、空格也不可以)

二、

javascript()函式(常用、推薦)

舉個例子吧:

1、跳轉到本地的一個deom.html(立刻跳轉,沒有任何延遲)

<?php
header("content-type:text/html;charset=utf-8");
<script>
    window.location.href='deom.php';
</script>

2、跳轉到本地的一個deom.html(可以設定延遲時間,需定時器)

setTimeout—在指定的毫秒數後呼叫函式或計算表示式

<?php
header("content-type:text/html;charset=urf-8");
<script>
    setTimeout("window.location.href='deom.html'",3000);
</script>

分析:指令複雜,但是使用的範圍大,侷限性小。推薦使用