Common instructions based on headers _ PHP Tutorial

Source: Internet
Author: User
Tags http authentication 503 service temporarily unavailable
Detailed description of some common headers. Common header commands include HTTP-Version, Status, and Reason-Phrase ). Common header commands
The header is divided into three parts:
The first part is the HTTP Version );
The second part is the Status code );
The third part is the Reason Phrase (Reason-Phrase ).

// Fix 404 pages: Use this header command to solve the 404 header generated by URL rewriting.
Header ('http/1.1 200 OK ');

// Set 404 header: Page not found
Header ('http/1.1 404 Not Found ');

// The page is permanently deleted. you can tell the search engine to update their urls.
// Set Moved Permanently header (good for redrictions)
// Use with location header
Header ('http/1.1 301 Moved Permanently ');

// Restricted access
Header ('http/1.1 403 Forbidden ');

// Server error
Header ('http/1.1 500 Internal Server Error ');

// Redirect to a new location
// Redirect to a new location:
Header ('Location: http://www.example.org /');

Redirection after a delay of some time
// Redrict with delay:
Header ('refresh: 10; url = http://www.example.org /');
Print 'You will be redirected in 10 seconds ';

// Overwrite X-Powered-By value
// Override X-Powered-By: PHP:
Header ('x-Powered-By: PHP/4.4.0 ');
Header ('x-Powered-By: Brain/0.6b ');

// Content language (en = English)
// Content language (en = English)
Header ('content-language: en ');

// The last modification time (which can be used in cache)
// Last modified (good for caching)
$ Time = time ()-60; // or filemtime ($ fn), etc
Header ('last-Modified: '. gmdate ('d, d m y h: I: S', $ time). 'gmt ');

// Tell the browser that the content to be retrieved has not been updated
// Header for telling the browser that the content
// Did not get changed
Header ('http/1.1 304 Not modified ');

// Set the content length (which can be used for caching ):
// Set content length (good for caching ):
Header ('content-Length: 1234 ');

// Used to download an object:
// Headers for an download:
Header ('content-Type: application/octet-stream ');
Header ('content-Disposition: attachment; filename = "example.zip "');
Header ('content-Transfer-Encoding: binary ');

// Disable caching the current document:
// Load the file to send: readfile('example.zip ');
// Disable caching of the current document:
Header ('cache-Control: no-Cache, no-store, max-age = 0, must-revalidate ');
Header ('expires: Mon, 26 Jul 1997 05:00:00 GMT ');

// Set the content type:
// 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 file
Header ('content-Type: image/jpeg ');

// JPG picture
Header ('content-Type: application/zip ');

// ZIP file
Header ('content-Type: application/pdf ');

// PDF file
Header ('content-Type: audio/mpeg ');

// Audio MPEG (MP3,...) file
Header ('content-Type: application/x-shockwave-Flash ');

// The logon dialog box is displayed for HTTP authentication.
// Flash animation // show sign in 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';?>

// Send a 200 normal response
Header ("HTTP/1.1 200 OK ");

// Send a 404 error message indicating that the resource cannot be found
Header ('http/1.1 404 Not Found ');

// Send a 301 permanent redirect
Header ('http/1.1 301 Moved Permanently ');

// Send a 503 website temporarily inaccessible
Header ('http/1.1 503 Service Temporarily unavailable ');

// Webpage redirection
Header ('Location: http://www.jb51.net ');

// Set webpage redirection 3 seconds later
Header ('refresh: 3; url = http://www.jb51.net ');
Echo 'web page will jump to http://www.jb51.net in 3 seconds ';

// Sets the webpage encoding.
Header ('content-Type: text/html; charset = utf-8 ');

// Set a webpage to output an image stream
Header ('content-Type: image/jpeg ');

// Set the webpage to output a pdf document
Header ('content-Type: application/pdf ');

// Set the webpage to output a zip file
Header ('content-Type: application/zip ');

Expose header is divided into three parts: the first part is the HTTP protocol Version (HTTP-Version), the second part is the Status code (Status), and the third part is the Reason Phrase (Reason-Phrase )....

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.