Example of http packet header setting using PHPheader function

Source: Internet
Author: User
Tags http cookie ranges
: This article describes how to set an http packet header using the phphpheader function. if you are interested in the PHP Tutorial, refer to it.
// Define the encoding headers ('content-Type: text/html; charset = utf-8 '); // Atomheader ('content-type: application/atom + XML '); // CSSheader ('content-type: text/css '); // Javascriptheader ('content-type: text/javascript'); // JPEG Imageheader ('content-type: image/jpeg '); // JSONheader ('content-type: application/json'); // response header ('content-type: application/pdf '); // RSSheader ('content-Type: application/rss + xml; charset = ISO-8859-1 '); // Text (Plain) header ('content-type: text/plain '); // XMLheader ('content-type: text/XML'); // 200 OKheader ('http/1.1 200 OK '); // set a 404 header: header ('http/1.1 404 Not Found '); // Set the address to be Permanently redirected header ('http/1.1 301 Moved Permanently '); // go to a new address header ('Location: http://www.example.org/'); // File delay redirection: header ('refresh: 10; url = http://www.example.org /'); print 'You will be redirected in 10 seconds '; // of course, You can also use html syntax to implement //
 // Override X-Powered-By: PHP: header ('x-Powered-By: PHP/4.4.0 '); header ('x-Powered-: brain/0.6b '); // The header of the document language ('content-language: en'); // notify the browser of the last modification time $ time = time ()-60; // or filemtime ($ fn), etcheader ('last-Modified :'. gmdate ('d, d m y h: I: S', $ time ). 'gmt'); // tell the browser that the document Content has Not changed the header ('http/1.1 304 Not modified'); // set the Content Length header ('content-Length: 1234 '); // Set it to a download Type header ('content-Type: application/octet-stream'); header ('content-Disposition: attachment; filename = "example.zip" '); header ('content-Transfer-Encoding: binary'); // load the file to send: readfile('example.zip '); // disable the Cache header ('cache-Control: no-cache, no-store, max-age = 0, must-revalidate') for the current document; header ('expires: mon, 26 Jul 1997 05:00:00 GMT'); // Date in the pastheader ('pragma: no-cache'); // set the 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 format header ('content-Type: image/jpeg '); // JPG *** header ('content-Type: application/zip '); // ZIP file header ('content-Type: application/pdf '); // pdf file header ('content-Type: audio/mpeg '); // Audio File header ('content-Type: application/x-shockw ** e-Flash '); // Flash animation // display the login dialog 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 ';
# Appendix: Requests for HTTP header details
Header Explanation Example
Accept Specifies the content type that the client can receive Accept: text/plain, text/html
Accept-Charset String set that the browser can accept. Accept-Charset: ISO-8859-5
Accept-Encoding Specifies the type of content compression encoding that can be returned by the web server supported by the browser. Accept-Encoding: compress, gzip
Accept-Language Acceptable browser language Accept-Language: en, zh
Accept-Ranges You can request one or more sub-range fields of a webpage object. Accept-Ranges: bytes
Authorization HTTP authorization certificate Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ =
Cache-Control Specify the cache mechanism for requests and responses Cache-Control: no-cache
Connection Indicates whether a persistent connection is required. (HTTP 1.1 performs persistent connections by default) Connection: close
Cookie When an HTTP request is sent, all cookie values stored under the domain name of the request are sent to the web server. Cookie: $ Version = 1; Skin = new;
Content-Length Request content length Content-Length: 348
Content-Type MIME Information of the request corresponding to the object Content-Type: application/x-www-form-urlencoded
Date Date and time when the request was sent Date: Tue, 15 Nov 2010 08:12:31 GMT
Secondary CT Specific server behavior of the request Secondary CT: 100-continue
From Email of the user sending the request From: user@email.com
Host Specify the domain name and port number of the requested server Host: www.zcmhi.com
If-Match Valid only when the request content matches the object If-Match: "737060cd8c284d8af7ad3082f209582d"
If-Modified-Since If the request is modified after the specified time, the request is successful. if the request is not modified, code 304 is returned. If-Modified-Since: Sat, 29 Oct 2010 19:43:31 GMT
If-None-Match If the content is not changed, the system returns the 304 code. the parameter is the Etag previously sent by the server. compare it with the Etag responded by the server to determine whether the Etag is changed. If-None-Match: "737060cd8c284d8af7ad3082f209582d"
If-Range If the entity has not changed, the server sends the part lost by the client; otherwise, the whole entity is sent. The parameter is also Etag. If-Range: "737060cd8c284d8af7ad3082f209582d"
If-Unmodified-Since The request is successful only when the object is not modified after the specified time. If-Unmodified-Since: Sat, 29 Oct 2010 19:43:31 GMT
Max-Forwards Restrict the time when information is transmitted through the proxy and Gateway Max-Forwards: 10
Pragma Used to include specific instructions Pragma: no-cache
Proxy-Authorization Connect to the proxy authorization certificate Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ =
Range Request only part of the object, specifying the range Range: bytes = 500-999
Referer The address of the previous webpage, followed by the current requested webpage. Referer: http://www.zcmhi.com/archives/71.html
TE The client is willing to accept the transfer code and notifies the server to accept the tail header information. TE: trailers, deflate; q = 0.5
Upgrade Specify a certain transmission protocol to the server for server conversion (if supported) Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11
User-Agent The User-Agent content contains the User information that sends the request. User-Agent: Mozilla/5.0 (Linux; X11)
Via Notify the intermediate gateway or proxy server address, communication protocol Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
Warning Message entity warning information Warn: 199 Miscellaneous warning

Responses section

Header Explanation Example
Accept-Ranges Indicates whether the server supports specified range requests and the type of segmented requests Accept-Ranges: bytes
Age Estimated time from the origin server to the proxy cache (in seconds, non-negative) Age: 12
Allow Valid request behavior for a network resource. if the request is not allowed, 405 is returned. Allow: GET, HEAD
Cache-Control Tell all cache mechanisms whether they can be cached or not Cache-Control: no-cache
Content-Encoding The compression encoding type of the returned content supported by the web server. Content-Encoding: gzip
Content-Language Response body language Content-Language: en, zh
Content-Length Response body length Content-Length: 348
Content-Location Another alternative address that the requested resource can replace Content-Location:/index.htm
Content-MD5 Returns the MD5 checksum of the resource. Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ =
Content-Range Bytes in the whole returned body Content-Range: bytes 21010-47021/47022
Content-Type MIME type of returned content Content-Type: text/html; charset = utf-8
Date Time when the original server message was sent Date: Tue, 15 Nov 2010 08:12:31 GMT
ETag Current value of the object tag of the request variable ETag: "737060cd8c284d8af7ad3082f209582d"
Expires Response expiration date and time Expires: Thu, 01 Dec 2010 16:00:00 GMT
Last-Modified Last modification time of the requested resource Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT
Location Used to redirect the recipient to a location other than the requested URL to complete the request or identify a new resource Location: http://www.zcmhi.com/archives/94.html
Pragma Includes the implementation of specific commands that can be applied to any receiver on the response chain. Pragma: no-cache
Proxy-Authenticate It specifies the authentication scheme and the parameters that can be applied to the URL of the proxy. Proxy-Authenticate: Basic
Refresh Apply to redirection or a new resource is created and redirected in 5 seconds (proposed by Netscape and supported by most browsers)

Refresh: 5; url =

Http://www.zcmhi.com/archives/94.html

Retry-After If the object 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 Indicates that the header field exists at the end of the multipart transfer encoding. Trailer: Max-Forwards
Transfer-Encoding File transfer encoding Transfer-Encoding: chunked
Vary Tell the downstream proxy whether to use cache response or request from the original server Vary :*
Via Tell the proxy client where the response is sent Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
Warning Warning possible entity problems Warning: 199 Miscellaneous warning
WWW-Authenticate Indicates the authorization scheme that the client request entity should use WWW-Authenticate: Basic

OriginalHttp://blog.csdn.net/wyqwclsn/article/details/41082083

The above describes the example of setting an http packet header by using the PHP header function, including the following content. I hope to help some friends who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.