The following small series for you to share a PHP header of the different usage summary (example), I believe many students at the beginning to know
PHPThe header is the declaration of the font encoding, then today is to break your previous
PHPIn the header. Let's take a look at it!
1. The function of the header () is to send an original HTTP header [HTTP header] to the client.
Header (String,replace,http_response_code)/*string: Required. Specifies the string of headers to send. Replace: Optional. Indicates whether the header replaces the previous header, or adds a second header. The default is true (replace). False (multiple headers of the same type are allowed). Http_response_code: Optional. Forces the HTTP response code to the specified value. */
Note: the header () function must be called before any actual output is sent.
2. Usage 1: Jump page
Header ("location:https://baidu.com"); Normal jump Header (' refresh:3; url=https://www.baidu.com '); 3s after jump//in the header for the jump, to avoid errors, the code continues to execute, generally add a exit;
Usage 2: declare content-type (which I often use to solve garbled characters)
Header (' Content-type:text/html;charset=utf-8 ');
Usage 3: return the response status code
Header (' http/1.1 403 Forbidden ');
Usage 4: perform the download operation (the location of the hidden file)
Header (' Content-type:application/octet-stream '); Set Content Type header (' content-disposition:attachment; filename= ' example.zip ');//set MIME user as Attachment header (' Content-transfer-encoding:binary '); Set the Transmit mode header (' Content-length: '. FileSize (' Example.zip ')); Set Content length
Usage 5: Control Browser caching
Header (' Expires:mon, Jul 1997 05:00:00 GMT '); If the page on the server changes frequently, set it to-1, which indicates an immediate expiration header (' last-modified: '. Gmdate (' d, D M Y h:i:s '). ' GMT '); header (' Cache-control:no-store, No-cache, Must-revalidate '); header (' Cache-control:post-check=0, pre-check= 0 ', false); header (' Pragma:no-cache ');
Usage 6:
3. More examples
<?php//okheader (' http/1.1 OK ');//Set a 404 Header: Header (' http/1.1 404 Not Found ');//Set address is permanently redirected header (' http/1.1 301 Moved permanently ');//Go to a new address header (' location:http://www.example.org/');//File Delay Turn: header (' Refresh:10; url=http:// www.example.org/');p rint ' You'll be being redirected in seconds ';//Of course, you can also use HTML syntax to implement//<meta http-equiv= "Refresh" Content= "10;http://www.example.org//>//override X-powered-by:php:header (' x-powered-by:php/4.4.0 '); Header (' x-powered-by:brain/0.6b ');//Document Language header (' content-language:en ');//Tell the browser the last modification 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 header (' http/1.1 304 not Modified ');//Set Content Length header (' content-length:1234 ');// Set 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 for the current document (' Cache-control:no-cAche, No-store, max-age=0, Must-revalidate '); header (' Expires:mon, Jul 1997 05:00:00 GMT '); Date in the Pastheader (' Pragma:no-cache ');//Set 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 Image 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-shockwave-flash '); Flash animation//Display Login Dialog header (' http/1.1 401 Unauthorized '); header (' Www-authenticate:basic realm= ' Top Secret "');p rint ' Text that would be displayed if the user hits cancel or ';p rint ' enters wrong login data ';? >
The above PHP header of the different usage summary (example) is the small part to share the whole content of everyone.
Related recommendations:
Summary of usage of PHP header function
Several types of PHP header common URL address jump method
How to use HTML