header常用指令<br />header分為三部分:<br />第一部分為HTTP協議的版本(HTTP-Version);<br />第二部分為狀態碼(Status);<br />第三部分為原因短語(Reason-Phrase)。<br />// fix 404 pages: 用這個header指令來解決URL重寫產生的404 header<br />header(’HTTP/1.1 200 OK’);<br />// set 404 header: 頁面沒找到<br />header(’HTTP/1.1 404 Not Found’);<br />//頁面被永久刪除,可以告訴搜尋引擎更新它們的urls<br />// set Moved Permanently header (good for redrictions)<br />// use with location header<br />header(’HTTP/1.1 301 Moved Permanently’);<br />// 訪問受限<br />header(’HTTP/1.1 403 Forbidden’);<br />// 伺服器錯誤<br />header(’HTTP/1.1 500 Internal Server Error’);<br />// 重新導向到一個新的位置<br />// redirect to a new location:<br />header(’Location: http://www.example.org/‘);<br />延遲一段時間後重新導向<br />// redrict with delay:<br />header(’Refresh: 10; url=http://www.example.org/’);<br />print ‘You will be redirected in 10 seconds’;<br />// 覆蓋 X-Powered-By value<br />// override X-Powered-By: PHP:<br />header(’X-Powered-By: PHP/4.4.0′);<br />header(’X-Powered-By: Brain/0.6b’);<br />// 內容語言 (en = English)<br />// content language (en = English)<br />header(’Content-language: en’);<br />//最後修改時間(在緩衝的時候可以用到)<br />// last modified (good for caching)<br />$time = time() – 60; // or filemtime($fn), etc<br />header(’Last-Modified: ‘.gmdate(’D, d M Y H:i:s’, $time).’ GMT’);<br />// 告訴瀏覽器要擷取的內容還沒有更新<br />// header for telling the browser that the content<br />// did not get changed<br />header(’HTTP/1.1 304 Not Modified’);<br />// 設定內容的長度 (緩衝的時候可以用到):<br />// set content length (good for caching):<br />header(’Content-Length: 1234′);<br />// 用來下載檔案:<br />// Headers for an download:<br />header(’Content-Type: application/octet-stream’);<br />header(’Content-Disposition: attachment; filename=”example.zip”‘);<br />header(’Content-Transfer-Encoding: binary’);<br />// 禁止緩衝當前文檔:<br />// load the file to send:readfile(’example.zip’);<br />// Disable caching of the current document:<br />header(’Cache-Control: no-cache, no-store, max-age=0, must-revalidate’);<br />header(’Expires: Mon, 26 Jul 1997 05:00:00 GMT’);<br />// 設定內容類型:<br />// Date in the pastheader(’Pragma: no-cache’);<br />// set content type:<br />header(’Content-Type: text/html; charset=iso-8859-1′);<br />header(’Content-Type: text/html; charset=utf-8′);<br />header(’Content-Type: text/plain’);<br />// plain text file<br />header(’Content-Type: image/jpeg’);<br />// JPG picture<br />header(’Content-Type: application/zip’);<br />// ZIP file<br />header(’Content-Type: application/pdf’);<br />// PDF file<br />header(’Content-Type: audio/mpeg’);<br />// Audio MPEG (MP3,…) file<br />header(’Content-Type: application/x-shockwave-flash’);<br />// 顯示登入對話方塊,可以用來進行HTTP認證<br />// Flash animation// show sign in box<br />header(’HTTP/1.1 401 Unauthorized’);<br />header(’WWW-Authenticate: Basic realm=”Top Secret”‘);<br />print ‘Text that will be displayed if the user hits cancel or ‘;<br />print ‘enters wrong login data’;