<span>//定义编码
header( <span>'Content-Type:text/html;charset=utf-8 ');
<span>//Atom
header(<span>'Content-type: application/atom+xml');
<span>//CSS
header(<span>'Content-type: text/css');
<span>//Javascript
header(<span>'Content-type: text/javascript');
<span>//JPEG Image
header(<span>'Content-type: image/jpeg');
<span>//JSON
header(<span>'Content-type: application/json');
<span>//PDF
header(<span>'Content-type: application/pdf');
<span>//RSS
header(<span>'Content-Type: application/rss+xml; charset=ISO-8859-1');
<span>//Text (Plain)
header(<span>'Content-type: text/plain');
<span>//XML
header(<span>'Content-type: text/xml');
<span>//200 OK
header(<span>'HTTP/1.1 200 OK');
<span>//设置一个404头:
header(<span>'HTTP/1.1 404 Not Found');
<span>//设置地址被永久的重定向
header(<span>'HTTP/1.1 301 Moved Permanently');
<span>//转到一个新地址
header(<span>'Location: http://www.example.org/');
<span>//文件延迟转向:
header(<span>'Refresh: 10; url=http://www.example.org/');
<span>print <span>'You will be redirected in 10 seconds';
<span>//当然,也可以使用html语法实现
<span>//<meta http-equiv="refresh" c>//override X-Powered-By: PHP:
header(<span>'X-Powered-By: PHP/4.4.0');
header(<span>'X-Powered-By: Brain/0.6b');
<span>//文档语言
header(<span>'Content-language: en');
<span>//告诉浏览器最后一次修改时间
<span>$time = time() - <span>60; <span>// or filemtime($fn), etc
header(<span>'Last-Modified: '.gmdate(<span>'D, d M Y H:i:s', <span>$time).<span>' GMT');
<span>//告诉浏览器文档内容没有发生改变
header(<span>'HTTP/1.1 304 Not Modified');
<span>//设置内容长度
header(<span>'Content-Length: 1234');
<span>//设置为一个下载类型
header(<span>'Content-Type: application/octet-stream');
header(<span>'Content-Disposition: attachment; filename="example.zip"');
header(<span>'Content-Transfer-Encoding: binary');
<span>//load the file to send:
readfile(<span>'example.zip');
<span>//对当前文档禁用缓存
header(<span>'Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header(<span>'Expires: Mon, 26 Jul 1997 05:00:00 GMT'); <span>// Date in the past
header(<span>'Pragma: no-cache');
<span>//设置内容类型:
header(<span>'Content-Type: text/html; charset=iso-8859-1');
header(<span>'Content-Type: text/html; charset=utf-8');
header(<span>'Content-Type: text/plain'); <span>//纯文本格式
header(<span>'Content-Type: image/jpeg'); <span>//JPG***
header(<span>'Content-Type: application/zip'); <span>// ZIP文件
header(<span>'Content-Type: application/pdf'); <span>// PDF文件
header(<span>'Content-Type: audio/mpeg'); <span>// 音频文件
header(<span>'Content-Type: application/x-shockw**e-flash'); <span>//Flash动画
<span>//显示登陆对话框
header(<span>'HTTP/1.1 401 Unauthorized');
header(<span>'WWW-Authenticate: Basic realm="Top Secret"');
<span>print <span>'Text that will be displayed if the user hits cancel or ';
<span>print <span>'enters wrong login data';</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br>
登入後複製
#附:HTTP header 詳解
Requests部分
Header |
解釋 |
用text/html |
Accept-Charset |
瀏覽器可以接受的字元編碼集。 |
Accept-Charset: iso-8859-5 |
Accept-Encoding |
指定瀏覽器可以支援的web伺服器傳回內容壓縮編碼類型。 |
Accept-Encoding: compress, gzip |
Accept-Language |
瀏覽器可接受的語言 |
Accept-Language: en,zh |
Accept-Language: en,zh🜎個子範圍欄位 | Accept-Ranges: bytes |
| Authorization
HTTP授權的授權憑證 | Authorization: Basicache QWxhZpbache指定請求和回應遵循的快取機制 | Cache -Control: no-cache |
Connection | 表示是否需要持久連線。 (HTTP 1.1預設進行持久連接) | Connection: close |
Cookie | HTTP請求發送時,會把保存在該請求網域下的所有cookie值一起傳送給web伺服器。 | Cookie: $Version=1; Skin=new; |
Content-Length | 請求的內容長度 | Content-Length: 348 |
Content-Length: 348 |
| Content |
Content-Type: application/x-www-form-urlencoded
|
Date |
請求發送的日期和時間 |
Date: Tue, 15 Nov 2010 08:12:31 GMT
|
Expect |
要求的特定的伺服器行為 |
Expect: 100-continue
|
From |
發出請求的使用者的Email |
From: user@email.com號碼
Host: www.zcmhi.com |
|
If-Match |
只有請求內容與實體相匹配才有效
If-Match: “737060cd8c284d87508845” ified-Since |
如果請求的部分在指定時間之後被修改則請求成功,未被修改則回傳304代碼 |
If-Modified-Since: Sat, 29 Oct 2010 19:43:31 GMT |
If-None-Match |
|
If-None-Matchn內容未改變回傳304代碼,參數為伺服器先前發送的Etag,與伺服器回應的Etag比較判斷是否改變 |
If-None-Match: “737060cd8c284d8af7ad3082f209582d”
|
發送客戶端遺失的部分,否則發送整個實體。參數也為Etag |
If-Range: “737060cd8c284d8af7ad3082f209582d” |
If-Unmodified-Since Octofer | 2010 19:43:31 GMT |
| Max-Forwards
限制訊息透過代理和閘道傳送的時間 | Max-Forwards: 10 | 瑪-cache |
Proxy-Authorization | 連接到代理的授權憑證 | Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== | Range: bytes=500- 999
| Referer | 先前網頁的地址,當前請求網頁緊跟在後,即來路 | Referer: http://www.zcmhi.com/archives/71.html
|
客戶端願意接受的傳輸編碼,並通知伺服器接受接受尾加頭資訊 |
TE: trailers,deflate;q=0.5 |
Upgrade |
向伺服器指定某種傳輸協定以便伺服器進行轉換(如果支援) |
Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11 |
User-Agent |
User-Agent的內容包含發出所要求的使用者資訊 | ; X11) |
Via | 通知中間網關或代理伺服器位址,通訊協定 | Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1) |
Warn: 199 Miscellaneous warning |
|
Responses 部分
Header |
解釋 |
範例 |
Accept-Ranges | :請表明是否支援使用類型的分段範圍、 | Age | 從原始伺服器到代理快取形成的估算時間(以秒計,非負)
Age: 12 |
| Allow | 對某網絡資源的有效的請求行為,不允許則返回4055 Allow: GET, HEAD
| Cache-Control | 告訴所有的快取機制是否可以快取及哪種類型 | Cache-Control: no-cache
Cont壓縮編碼類型。 |
Content-Encoding: gzip |
|
Content-Language
響應體的語言 |
Content-Language: en,zhcom : 348 | |
Content-Location
請求資源可替代的備用的另一地址 |
Content-Location: /index.htm |
|
Content-MD5: 7525:67575接合值回傳Q2hlY2sgSW50ZWdyaXR5IQ== |
| Content-Range | 在整個回傳體中本部分的位元組位置
Content-Range: byp回傳內容的MIME類型 | Content-Type: text/html; charset=utf-8 |
| Date
原始伺服器訊息發出的時間 | Date: Tue, 15 Nov 2010 08:12:31 GMT | 變數的實體標籤的目前值 | ETag: “737060cd8c284d8af7ad3082f209582d”
| Expires | 回應過期的日期和時間和時間點 |
Last-Modified 請求資源的最後修改時間 |
Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT |
|
Location
用來完成請求或直接的請求資源 |
Location: http://www.zcmhi.com/archives/94.html |
|
Pragma
包括實作特定的指令,它可應用到回應鏈上的任何接收方 | maPragma: no- cache |
|
Proxy-Authenticate
它指出認證方案和可應用到代理的該URL上的參數 |
Proxy-Authenticate: Basic |
|
Proxy-Authenticate: Basic
,在5秒之後重定向(由網景提出,被大部分瀏覽器支援) |
| Refresh: 5; url= | http://www.zcmhi.com/archives/94.html
| Retry-After |
如果實體暫時不可取,通知客戶端在指定時間之後再嘗試 |
Retry-After: 120
|
Server |
UR伺服器軟體名稱 |
Server: ) (Red-Hat/Linux)
|
Set-Cookie |
設定Http Cookie |
Set-Cookie:UserID=JohnDoe; Max-Age=3600; Version=1分塊傳輸編碼的尾端存在 | Trailer: Max-Forwards |
Transfer-Encoding
檔案傳輸編碼
| Transfer-Encoding:chunked 檔案傳送編碼
Transfer-Encoding:chunked伺服器請求 |
Vary: * |
|
Via
告知代理客戶端回應是透過哪裡發送的 |
Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)🎟存在的問題 |
Warning: 199 Miscellaneous warning |
WWW-Authenticate |
表明客戶端請求實體應該使用的授權方案 |
WWW-Authenticate: Basic |
|
原文 | http://blog. csdn.net/wyqwclsn/article/details/41082083
|
以上就介紹了PHP header函數設定http報文頭範例詳解,包括了方面的內容,希望對PHP教學有興趣的朋友有所幫助。
|
|