基于header的一些常用指令詳解
header常用指令
header分為三部分:
第一部分為HTTP協(xié)議的版本(HTTP-Version);
第二部分為狀態(tài)代碼(Status);
第三部分為原因短語(Reason-Phrase)。
// fix 404 pages: 用這個(gè)header指令來解決URL重寫產(chǎn)生的404 header
header('HTTP/1.1 200 OK');
// set 404 header: 頁面沒找到
header('HTTP/1.1 404 Not Found');
//頁面被永久刪除,可以告訴搜索引擎更新它們的urls
// set Moved Permanently header (good for redrictions)
// use with location header
header('HTTP/1.1 301 Moved Permanently');
// 訪問受限
header('HTTP/1.1 403 Forbidden');
// 服務(wù)器錯(cuò)誤
header('HTTP/1.1 500 Internal Server Error');
// 重定向到一個(gè)新的位置
// redirect to a new location:
header('Location: http://www.example.org/');
延遲一段時(shí)間后重定向
// redrict with delay:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
// 覆蓋 X-Powered-By value
// override X-Powered-By: PHP:
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');
// 內(nèi)容語言 (en = English)
// content language (en = English)
header('Content-language: en');
//最后修改時(shí)間(在緩存的時(shí)候可以用到)
// last modified (good for caching)
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
// 告訴瀏覽器要獲取的內(nèi)容還沒有更新
// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');
// 設(shè)置內(nèi)容的長(zhǎng)度 (緩存的時(shí)候可以用到):
// set content length (good for caching):
header('Content-Length: 1234');
// 用來下載文件:
// Headers for an download:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// 禁止緩存當(dāng)前文檔:
// load the file to send:readfile('example.zip');
// Disable caching of the current document:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// 設(shè)置內(nèi)容類型:
// Date in the pastheader('Pragma: no-cache');
// set content type:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain');
// plain text file
header('Content-Type: image/jpeg');
// JPG picture
header('Content-Type: application/zip');
// ZIP file
header('Content-Type: application/pdf');
// PDF file
header('Content-Type: audio/mpeg');
// Audio MPEG (MP3,...) file
header('Content-Type: application/x-shockwave-flash');
// 顯示登錄對(duì)話框,可以用來進(jìn)行HTTP認(rèn)證
// Flash animation// show sign in box
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';?>
// 發(fā)送一個(gè)200 正常響應(yīng)
header("HTTP/1.1 200 OK");
// 發(fā)送一個(gè)404 找不到資源響應(yīng)
header('HTTP/1.1 404 Not Found');
// 發(fā)送一個(gè)301 永久重定向
header('HTTP/1.1 301 Moved Permanently');
// 發(fā)送一個(gè)503 網(wǎng)站暫時(shí)不能訪問
header('HTTP/1.1 503 Service Temporarily Unavailable');
// 網(wǎng)頁重定向
header('Location: http://www.dbjr.com.cn');
// 設(shè)置網(wǎng)頁3秒后重定向
header('Refresh: 3; url=http://www.dbjr.com.cn');
echo '網(wǎng)頁將在3秒后跳轉(zhuǎn)到http://www.dbjr.com.cn';
// 設(shè)置網(wǎng)頁編碼
header('Content-Type: text/html; charset=utf-8');
// 設(shè)置網(wǎng)頁輸出一個(gè)圖片流
header('Content-Type: image/jpeg');
// 設(shè)置網(wǎng)頁輸出一個(gè)pdf文檔
header('Content-Type: application/pdf');
// 設(shè)置網(wǎng)頁輸出一個(gè)zip文檔
header('Content-Type: application/zip');
相關(guān)文章
mysql 查詢指定日期時(shí)間內(nèi)sql語句實(shí)現(xiàn)原理與代碼
查詢指定日期時(shí)間內(nèi)sql語句實(shí)現(xiàn)原理:如果是月份就是當(dāng)前的月減去你要統(tǒng)計(jì)的時(shí)間如我要查詢數(shù)據(jù)庫中從今天起往前三個(gè)月的所有記錄2012-12-12PHP實(shí)現(xiàn)刪除字符串中任何字符的函數(shù)
這篇文章主要介紹了PHP實(shí)現(xiàn)刪除字符串中任何字符的函數(shù),涉及php針對(duì)字符串的遍歷與截取操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08php flush無效,IIS7下php實(shí)時(shí)輸出的方法
這篇文章主要介紹了php flush無效,IIS7下php實(shí)時(shí)輸出的方法,需要的朋友可以參考下2016-08-08PHP基于接口技術(shù)實(shí)現(xiàn)簡(jiǎn)單的多態(tài)應(yīng)用完整實(shí)例
這篇文章主要介紹了PHP基于接口技術(shù)實(shí)現(xiàn)簡(jiǎn)單的多態(tài)應(yīng)用,結(jié)合完整實(shí)例形式分析了php接口的定義、繼承、調(diào)用及多態(tài)的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-04-04php查看當(dāng)前Session的ID實(shí)例
這篇文章主要介紹了php查看當(dāng)前Session的ID的方法,實(shí)例分析了兩種常見的獲取session中ID的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03