1. 程式人生 > >PHP基礎知識之頁面跳轉

PHP基礎知識之頁面跳轉

一.header指令頁面跳轉

1.header("location:regieter.html");//不友好直接跳轉到那個頁面
2.header("refresh:3;url=register.html");//延遲3秒頁面跳轉
die("非法訪問,請訪問註冊頁面");

 二javascript頁面跳轉

1. echo "<script> window.location.href='register.html'; </script>";//直接跳轉
2. echo '非法訪問等待跳轉...'
   echo <<<AAA
   <script>
    setTimeout("window.location.href='register.html'",3000);
   </script>
   AAA;//前邊不能有空格
   exit;

計時器:setInterval:每間隔一段時間執行一次

              setTimeout:只執行一次 

 總結:頁面跳轉可以用header指令也可用JavaScript指令碼實現

 區別:header指令簡單但header指令前邊不能有任何輸出否則報錯(可寫後邊)

        <?php前有空格空行也會報錯,但JS指令碼不會受這些限制所以用JS指令碼頁面跳轉多