HTTP protocol for header usage in PHP and Common methods summary _php tips

Source: Internet
Author: User

This article summarizes the HTTP protocol used by header in PHP and the common methods. Share to everyone for your reference. The specific methods are as follows:

Copy Code code as follows:
? Php
function HTTPS ($num) {
$http = Array (
=> "http/1.1 Continue",
=> "http/1.1 switching Protocols",
=> "http/1.1 OK",
201 => "http/1.1 201 Created",
=> "http/1.1 accepted",
203 => "http/1.1 203 non-authoritative Information",
204 => "http/1.1 204 No Content",
205 => "http/1.1 205 Reset Content",
206 => "http/1.1 206 Partial Content",
=> "http/1.1 Multiple Choices",
The => "http/1.1 moved Permanently",
302 => "http/1.1 302 Found",
303 => "http/1.1 303 to Other",
304 => "http/1.1 304 not Modified",
305 => "http/1.1 305 use Proxy",
307 => "http/1.1 307 temporary Redirect",
=> "http/1.1 bad Request",
401 => "http/1.1 401 Unauthorized",
402 => "http/1.1 402 Payment Required",
403 => "http/1.1 403 Forbidden",
404 => "http/1.1 404 Not Found",
405 => "http/1.1 405 method is not allowed",
406 => "http/1.1 406 not acceptable",
407 => "http/1.1 407 Proxy authentication Required",
408 => "http/1.1 408 Request time-out",
409 => "http/1.1 409 Conflict",
410 => "http/1.1 410 Gone",
411 => "http/1.1 411 Length Required",
412 => "http/1.1 412 precondition Failed",
413 => "http/1.1 413 Request Entity Too",
414 => "http/1.1 414 Request-uri Too",
415 => "http/1.1 415 unsupported Media Type",
416 => "http/1.1 416 requested range not satisfiable",
417 => "http/1.1 417 expectation Failed",
=> "http/1.1 Internal Server Error",
501 => "http/1.1 501 Not implemented",
502 => "http/1.1 502 Bad Gateway",
503 => "http/1.1 503 Service Unavailable",
504 => "http/1.1 504 Gateway Time-out"
);
Header ($http [$num]);
};

200 normal state
Header (' http/1.1 OK ');

301 permanent Redirect, remember to add a redirect to the following address Location: $url
Header (' http/1.1 moved Permanently ');

Redirect, in fact, is 302 temporarily redirected
Header (' location:http://www.xxxx.com/');

Set page 304 without modification
Header (' http/1.1 304 not Modified ');

Display the Login box,
Header (' http/1.1 401 Unauthorized ');
Header (' Www-authenticate:basic realm= ' login information ');
Echo ' Displays the information! ';

403 No Access
Header (' http/1.1 403 Forbidden ');

404 error
Header (' http/1.1 404 Not Found ');

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

REDIRECT the specified address after 3 seconds (that is, refreshing to the new page is the same as <meta http-equiv= "Refresh content=" 10;http://www.xxxx.com//>)
Header (' Refresh:3; url=http://www.xxxx.com/');
Echo ' 10 jump to http://www.xxxx.com ';

overriding x-powered-by values
Header (' x-powered-by:php/5.3.0 ');
Header (' x-powered-by:brain/0.6b ');

Setting the context language
Header (' content-language:en ');

Set the last time the page was modified (more for anti-caching)
$time = time ()-60; It is recommended that you use the FILETIME function to set page cache time
Header (' last-modified: ' Gmdate (' d, D M Y h:i:s ', $time). ' GMT ');

Set Content length
Header (' content-length:39344 ');

Sets the header file type, which can be used for streaming files or file downloads
Header (' Content-type:application/octet-stream ');
Header (' content-disposition:attachment; filename= "Example.zip");
Header (' content-transfer-encoding:binary ');
ReadFile (' example.zip ');//Read files to Client

disabling page Caching
Header (' Cache-control:no-cache, No-store, max-age=0, Must-revalidate ');
Header (' Expires:mon, June 1997 05:00:00 GMT ');
Header (' Pragma:no-cache ');

Set Page header information
Header (' content-type:text/html; charset=iso-8859-1 ');
Header (' content-type:text/html; Charset=utf-8 ');
Header (' Content-type:text/plain ');
Header (' Content-type:image/jpeg ');
Header (' Content-type:application/zip ');
Header (' content-type:application/pdf ');
Header (' Content-type:audio/mpeg ');
Header (' Content-type:application/x-shockwave-flash ');
//.... As for the Content-type value, you can check the document library of the consortium, which is rich
?>

I hope this article will help you with your PHP program design.

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.