%@LANGUAGE="VBSCRIPT" CODEPAGE="950"%>
文件標題:[D002]常用函數介紹(二)header函數與HTTP檔頭資訊
內容說明:
教學內容:
1、header函數使用location網頁導向
利用header函數與HTTP的檔頭資訊一起使用的功能,header函數的使用必須在資料輸出之前,所以要寫在所有語法之前,包括資料輸出或<HTML>標籤之前。
A、語法:header("檔頭資訊名稱:檔頭內容");
B、範例:
(1)、導向到某一個網址
<?php header("location: http://www.many.com.tw")?>
(2)、導向到目錄的某一檔案
<?php header("location: simple.php")?>
(3)、導向到「HTTP 404 - 找不到檔案」的錯誤訊息
<?php header("HTTP/1.0 404 Not Found");?>
C、錯誤寫法:
(1)、使用header之前不可有資料輸出
<?php echo "錯誤寫法"?> <?php header("location: http://www.many.com.tw")?>
(2)、使用header不可在Html標籤內
<html> <head><title>錯誤寫法</title></head> <body> <?php header("location: http://www.many.com.tw")?> </body>
2、header函數使用refresh網頁重讀及網頁導向
A、語法:
語法一:header("refresh:秒數") 語法二:header("refresh:秒數";url=導向的網址或目錄檔案)
(1)、五秒後自動重新整理網頁
<?php header("refresh:5")?>
(2)、五秒後導向到網址
<?php header("refresh:5 ; url=http://www.many.com.tw")?>