php常用header狀態

2021-09-05 18:21:55 字數 1893 閱讀 6288

<?php  

//200 正常狀態

// 301 永久重定向,記得在後面要加重定向位址 location:$url

// 重定向,其實就是302 暫時重定向

header('location: ');

// 設定頁面304 沒有修改

// 顯示登入框,

header('www-authenticate: basic realm="登入資訊"');

echo '顯示的資訊!';

// 403 禁止訪問

// 404 錯誤

// 500 伺服器錯誤

// 3秒後重定向指定位址(也就是重新整理到新頁面與 相同)

header('refresh: 3; url=');

echo '10後跳轉到';

// 重寫 x-powered-by 值

header('x-powered-by: php/5.3.0');

header('x-powered-by: brain/0.6b');

//設定上下文語言

header('content-language: en');

// 設定頁面最後修改時間(多用於防快取)

$time = time() - 60; //建議使用filetime函式來設定頁面快取時間

header('last-modified: '.gmdate('d, d m y h:i:s', $time).' gmt');

// 設定內容長度

header('content-length: 39344');

header('content-disposition: attachment; filename="example.zip"');

header('content-transfer-encoding: binary');

readfile('example.zip');//讀取檔案到客戶端

//禁用頁面快取

header('cache-control: no-cache, no-store, max-age=0, must-revalidate');

header('expires: mon, 26 jul 1997 05:00:00 gmt');

header('pragma: no-cache');

//設定頁面頭資訊

header('content-type: text/html; charset=iso-8859-1');

header('content-type: text/html; charset=utf-8');

header('content-type: text/plain');

header('content-type: image/jpeg');

header('content-type: audio/mpeg');

//.... 至於content-type 的值 可以去查查 w3c 的文件庫,那裡很豐富

?>

php常見header狀態

200 正常狀態 301 永久重定向,記得在後面要加重定向位址 location url 重定向,其實就是302 暫時重定向 header location 設定頁面304 沒有修改 顯示登入框,header www authenticate basic realm 登入資訊 echo 顯示的資訊!...

php常用HEADER頭記錄

設定此頁面的過期時間 用格林威治時間表示 只要是已經過去的日期即可。header expires mon,26 jul 1970 05 00 00 gmt 設定此頁面的最後更新日期 用格林威治時間表示 為當天,可以強制瀏覽器獲取最新資料 header last modified gmdate d,d...

郵件常用Header

使用php的mail函式做郵件傳送的例子 mail nobody example.com the subject message,from webmaster r n reply to webmaster r n x mailer php phpversion 更詳細的郵件頭資訊說明 reading...