顯示廣告
隱藏 ✕
看板 Knuckles_note
作者 Knuckles (站長 那克斯')
標題 [PHP] 跳轉頁面的三種方式
時間 2012年11月29日 Thu. PM 10:23:04


參考
 



1. header()

301: 永久轉移(Permanently Moved)

  header('HTTP/1.1 301 Moved Permanently');
  header("Location: http://disp.cc");

302: 暫時轉移(Temporarily Moved)

  header("Location: http://disp.cc");


 
  header("refresh:0; url=http://disp.cc")
上面的0代表要幾秒後refresh

注意 header() 前不可以有任何輸出 (不能有 echo ...)

     header() 後的程式也會被執行,記得加 die(); 或 exit;




2. Meta

echo '<meta http-equiv="refresh" content="0;url=http://disp.cc">';

content 裡面那個 0 代表馬上跳轉,可以改成要幾秒後再跳轉


3. JavaScript

echo "<script type='text/javascript'>"
    ."window.location.href='http://disp.cc'"
    ."</script>";  

--
※ 作者: Knuckles 時間: 2012-11-29 22:23:04
※ 編輯: Knuckles 時間: 2014-10-21 23:11:56
※ 看板: KnucklesNote 文章推薦值: 0 目前人氣: 0 累積人氣: 4543 
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇