How to Header Status Code in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 17:25:22
Original
2065 people have browsed it

As described in Mr. Peng Wuxing's "PHP BIBLE", the header can send the Status header, such as
header("Status: 404 Not Found");
?>
It can cause the user's browser to display a 404 error of file not found, but I tried this and it didn't work.
Later, I checked http related information on w3.org, and finally tried out how to display the status code (Status) in the header, and shared it with everyone.
In fact, it should be like this:

Header("http/1.1 403 Forbidden");
?>
The first part is the HTTP protocol version (HTTP-Version)
The second part is the status code (Status)
The third part is the reason phrase (Reason-Phrase)
The three parts are separated by a space, and there cannot be a carriage return in the middle. The first and second parts are required Yes, the third part is for people to read, you can write it or not or even write it randomly :).
Also, the output of this sentence must be on the first line of the Html file.
Below I give the meaning of each code (I found it from w3.org, it is authoritative enough):
* 1xx: Informational - Request received, continuing process
* 2xx: Success - The action was successfully received, understood,
and accepted
* 3xx: Redirection - Further action must be taken in order to
complete the request
* 4xx: Client Error - The request contains bad syntax or cannot be
fulfilled
* 5xx: Server Error - The server failed to fulfill an apparently
valid request


| "100" ; Continue
| "101" ; Switching Protocols
| "200" ; OK
| "201" ; Created
| "202" ; Accepted
| "203" ; Non-Authoritative Information
| "204" ; No Content
| "205" ; Reset Content
| "206" ; Partial Content
| "300" ; Multiple Choices
| "301" ; Moved Permanently
| "302" ; Moved Temporarily
| "303" ; See Other
| "304" ; Not Modified
| "305" ; Use Proxy
| "400" ; Bad Request
| "401" ; Unauthorized
| "402" ; Payment Required
| "403" ; Forbidden
| "404" ; Not Found
| "405" ; Method Not Allowed
| "406" ; Not Acceptable
| "407" ; Proxy Authentication Required
| "408" ; Request Time-out
| "409" ; Conflict
| "410" ; Gone
| "411" ; Length Required
| "412" ; Precondition Failed
| "413" ; Request Entity Too Large
| "414" ; Request-URI Too Large
| "415" ; Unsupported Media Type
| "500" ; Internal Server Error
| "501" ; Not Implemented
| "502" ; Bad Gateway
| "503" ; Service Unavailable
| "504" ; Gateway Time-out
| "505" ; HTTP Version not supported

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532066.htmlTechArticleAs described in Mr. Peng Wuxing's "PHP BIBLE", the header can send the Status header, such as header(" Status: 404 Not Found"); ?> can cause the user's browser to display a 404 error of file not found...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!