Home >Backend Development >PHP Tutorial >Detailed explanation of PHP header function setting http message header example
<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>
Header | Explanation | Example | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Accept | Specify the content type that the client can receive | Accept: text/plain, text/html | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Accept-Charset | The character encoding set that the browser can accept. | Accept-Charset: iso-8859-5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Accept-Encoding | Specifies the content compression encoding type returned by the web server that the browser can support. | Accept-Encoding: compress, gzip | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Accept-Language | Accept-Language: en,zh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
You can request one or more web page entities Sub-range field | Accept-Ranges: bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Authorization certificate for HTTP authorization | Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Specify the caching mechanism followed by requests and responses | Cache -Control: no-cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
indicates whether a persistent connection is required. (HTTP 1.1 uses persistent connections by default) | Connection: close | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When an HTTP request is sent, all cookie values stored in the requested domain name will be sent to the web server. | Cookie: $Version=1; Skin=new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Requested content length | Content-Length: 348 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The requested MIME information corresponding to the entity | Content-Type: application/x-www-form-urlencoded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The date and time the request was sent | Date: Tue, 15 Nov 2010 08:12:31 GMT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Specific server behavior requested | Expect: 100-continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Email of the user who made the request | From: user@email.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Specify the domain name and port of the requested server No. | Host: www.zcmhi.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Only valid if the request content matches the entity | If-Match: "737060cd8c284d8af7ad3082f209582d" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if requested If the part is modified after the specified time, the request is successful. If it has not been modified, a 304 code will be returned. If the content has not changed, a 304 code is returned. The parameter is the Etag previously sent by the server. Compare it with the Etag responded by the server to determine whether it has changed. If-None-Match: "737060cd8c284d8af7ad3082f209582d" | If-Range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If-Range: "737060cd8c284d8af7ad3082f209582d" | If-Unmodified-Since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If-Unmodified-Since: Sat, 29 Oct 2010 19:43:31 GMT | Max-Forwards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Max-Forwards: 10 | Pragma | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Pragma: no -cache | Proxy-Authorization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== | Range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Range: bytes=500- 999 | Referer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Referer: http://www.zcmhi.com/archives/71.html | TE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TE: trailers,deflate;q=0.5 | Upgrade | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11 | User-Agent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
User-Agent: Mozilla/5.0 (Linux ; | Warn: 199 Miscellaneous warning
Header | Explanation | Example |
---|---|---|
Accept-Ranges | Indicates whether the server supports specified range requests and what type of segmented requests | Accept-Ranges: bytes |
Age | Estimated time from origin server to proxy cache formation (in seconds, non-negative) | Age: 12 |
Allow | A valid request behavior for a certain network resource, if not allowed, return 405 | Allow: GET, HEAD |
Cache-Control | Tell all caching mechanisms whether they can be cached and which types | Cache-Control: no-cache |
Content-Encoding | The returned content supported by the web server Compression encoding type. | Content-Encoding: gzip |
Content-Language | The language of the response body | Content-Language: en,zh |
Content-Length | The length of the response body | Content-Length: 348 |
Content-Location | Request an alternative address for the resource | Content-Location: /index.htm |
Content-MD5 | Return the MD5 check value of the resource | Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ== |
Content-Range | The byte position of this part in the entire return body | Content-Range: bytes 21010-47021/47022 |
Content-Type | Return content MIME type | Content-Type: text/html; charset=utf-8 |
Date | The time when the original server message was sent | Date: Tue, 15 Nov 2010 08:12:31 GMT |
ETag | Request The current value of the variable's entity tag | ETag: "737060cd8c284d8af7ad3082f209582d" |
Expires | The date and time the response expires | Expires: Thu, 01 Dec 2010 16:00:00 GMT |
Last-Modified | The last modified time of the requested resource | Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT |
Location | Used to redirect the receiver to the location of the non-requested URL to complete the request or identify a new one Resource | Location: http://www.zcmhi.com/archives/94.html |
Pragma | includes implementation specific directives which can be applied to any receiver on the response chain | Pragma: no- cache |
Proxy-Authenticate | It indicates the authentication scheme and parameters that can be applied to the proxy on that URL | Proxy-Authenticate: Basic |
refresh | Applies to redirects or when a new resource is created , redirect after 5 seconds (proposed by Netscape, supported by most browsers) |
Refresh: 5; url= http://www.zcmhi.com/archives/94.html |
Retry-After | If the entity is temporarily unavailable, notify the client to try again after the specified time | Retry-After: 120 |
Server | web server software name | Server: Apache/1.3.27 (Unix ) (Red-Hat/Linux) |
Set-Cookie | Set Http Cookie | Set-Cookie: UserID=JohnDoe; Max-Age=3600; Version=1 |
Trailer | Point out the header field The tail of chunked transfer-encoding exists | Trailer: Max-Forwards |
Transfer-Encoding | File Transfer-Encoding | Transfer-Encoding: chunked |
Vary | tells the downstream proxy whether to use a cached response or from the original Server Request | Vary: * |
Via | tells the proxy where the client response was sent | Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1) |
Warning | Warning Entity Possible Problems | Warning: 199 Miscellaneous warning |
WWW-Authenticate | Indicates the authorization scheme that the client requesting entity should use | WWW-Authenticate: Basic |
Original text http://blog. csdn.net/wyqwclsn/article/details/41082083
The above introduces the detailed explanation of the example of setting the http message header by the PHP header function, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.