Table of Contents
#Attachment: HTTP header detailed explanation
Requests part
Home Backend Development PHP Tutorial Detailed explanation of PHP header function setting http message header example

Detailed explanation of PHP header function setting http message header example

Jul 29, 2016 am 09:02 AM
application content header http type

<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>
Copy after login

#Attachment: HTTP header detailed explanation

Requests part

Accept-RangesAuthorization Cache-ControlConnectionCookieContent-LengthContent-TypeDateExpectFromHostIf-MatchIf-Modified- SinceIf the entity has not changed, the server Send the client's missing parts, otherwise send the entire entity. The parameter is also EtagThe request is successful only if the entity has not been modified after the specified timeLimit the time when information is transmitted through proxies and gatewaysUsed to contain implementation-specific instructionsAuthorization certificate connected to the proxyOnly request a part of the entity, specify the rangeThe address of the previous webpage, the current requested webpage is immediately followed, that is, the way to go The transfer encoding that the client is willing to accept, and notifies the server to accept the tail plus header information Specify a certain transport protocol to the server for conversion by the server (if supported) The content of User-Agent contains the user information that made the requestWarn: 199 Miscellaneous warning

Responses section

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 ;
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.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1246
24
What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

What is http status code 403? What is http status code 403? Oct 07, 2023 pm 02:04 PM

HTTP status code 403 means that the server rejected the client's request. The solution to http status code 403 is: 1. Check the authentication credentials. If the server requires authentication, ensure that the correct credentials are provided; 2. Check the IP address restrictions. If the server has restricted the IP address, ensure that the client's IP address is restricted. Whitelisted or not blacklisted; 3. Check the file permission settings. If the 403 status code is related to the permission settings of the file or directory, ensure that the client has sufficient permissions to access these files or directories, etc.

Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

What are the uses of the Type keyword in Go? What are the uses of the Type keyword in Go? Sep 06, 2023 am 09:58 AM

The usage of the Type keyword in Go includes defining new type aliases or creating new structure types. Detailed introduction: 1. Type alias. Use the "type" keyword to create an alias for an existing type. This alias does not create a new type, but only provides a new name for the existing type. Type aliases can improve code. The readability of the code makes the code clearer; 2. Structure type. Use the "type" keyword to create a new structure type. The structure is a composite type that can be used to define custom types containing multiple fields. etc.

Solve Ubuntu mounting mobile hard disk error: unknown file system type exfat Solve Ubuntu mounting mobile hard disk error: unknown file system type exfat Jan 05, 2024 pm 01:18 PM

An error occurs when ubuntu mounts a mobile hard disk: mount: unknownfilesystemtype'exfat'. The processing method is as follows: Ubuntu13.10 or install exfat-fuse: sudoapt-getinstallexfat-fuseUbuntu13.04 or below sudoapt-add-repositoryppa:relan/exfatsudoapt-getupdatesudoapt-getinstallfuse- exfatCentOS Linux mount exfat format USB disk error solution to load extfa in CentOS

HTTP 200 OK: Understand the meaning and purpose of a successful response HTTP 200 OK: Understand the meaning and purpose of a successful response Dec 26, 2023 am 10:25 AM

HTTP Status Code 200: Explore the Meaning and Purpose of Successful Responses HTTP status codes are numeric codes used to indicate the status of a server's response. Among them, status code 200 indicates that the request has been successfully processed by the server. This article will explore the specific meaning and use of HTTP status code 200. First, let us understand the classification of HTTP status codes. Status codes are divided into five categories, namely 1xx, 2xx, 3xx, 4xx and 5xx. Among them, 2xx indicates a successful response. And 200 is the most common status code in 2xx

How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS Sep 26, 2023 am 11:19 AM

How to use NginxProxyManager to implement automatic jump from HTTP to HTTPS. With the development of the Internet, more and more websites are beginning to use the HTTPS protocol to encrypt data transmission to improve data security and user privacy protection. Since the HTTPS protocol requires the support of an SSL certificate, certain technical support is required when deploying the HTTPS protocol. Nginx is a powerful and commonly used HTTP server and reverse proxy server, and NginxProxy

What does linux header mean? What does linux header mean? Jul 18, 2023 pm 03:34 PM

The Linux header refers to the beginning of a file or data stream, which is used to contain metadata about the content. By correctly writing and using Header files, developers can better utilize system resources and improve code readability and Maintainability.

See all articles