The header () function is used to send the native HTTP header. Cannot have output before header ()!
1. About header information.
In the HTTP protocol, the HTTP message is: The request message sent by the client and the Respose response message sent by the server side.
Request message: HTTP header (Request line + request header) +http body (request body); Response message: HTTP header (status line + response header) +http body (response body)
The header information of this HTTP header is not the
Header information includes many things: see more: Www.cnblogs.com/aliang1992/p/6049578.html.
2. Examples of common header () functions:
The first: the "http/" will be used to calculate the HTTP status code to be sent.
For example, on an Apache server, where a PHP script handles a request for a nonexistent file, you want the script to respond to the correct status code.
<? PHP Header ("http/1.0 404 Not Found");? >
The second type: Starting with "Location:", it not only sends messages to the browser, but also returns a status code to the browser.
Popular point, is automatically jump to http://www.example.com/URL address.
<? PHP Header ("location:http://www.example.com/"); Exit ;? >
The Third Kind: the object type that starts with "Content-type:", tells the browser that the server responds.
For example: Application/xml text/xml and so on. Decide what form of browser handout, what encoding to read this file.
The fourth type: Specify the content attachment with "content-disposition:".
When the server side wants the client browser to send the file, if it is a browser-supported file type, it will usually be opened by default browser, such as Txt.jpg, will be displayed directly in the browser, if you need to prompt the user
The content-disposition should be used to deal with the preservation.
<? PHP Header ("Content-disposition", "Attachment;filename=xxx.txt");? <
Header of PHP ()