三秦IT网在线论坛's Archiver

蓝冰 发表于 2007-5-16 10:17

PHP中如何使用header发送头部信息

在照彭武兴先生的《PHP BIBLE》中所述,header可以送出Status标头,如 <BR><BR>header("Status: 404 Not Found"); <BR><BR>?&gt; <BR><BR>就可以让用户浏览器出现文件找不到的404错误,但是我试了这样是不行的。 <BR><BR>后来我到w3.org上查了http的相关资料,终于试出来了如何Header出状态代码(Status),与大家分享。 <BR><BR>其实应该是这样的: <BR><BR>Header("http/1.1 403 Forbidden"); <BR><BR>?&gt; <BR><BR>第一部分为HTTP协议的版本(HTTP-Version) <BR><BR>第二部分为状态代码(Status) <BR><BR>第三部分为原因短语(Reason-Phrase) <BR><BR>三部分中间用一个空格分开,且中间不能有回车,第一部分和第二部分是必需的,第三部分则是给人看的,可写可不写甚至乱写。 <BR><BR>还有,这一句的输出必须在Html文件的第一行。 <BR><BR>下面我给出各代码所代表的意思(是从w3.org上查到的,够权威了): <BR><BR>  * 1xx: Informational - Request received, continuing process <BR><BR>  * 2xx: Success - The action was successfully received, understood, <BR><BR>  and accepted <BR><BR>  * 3xx: Redirection - Further action must be taken in order to <BR><BR>  complete the request <BR><BR>  * 4xx: Client Error - The request contains bad syntax or cannot be <BR><BR>  fulfilled <BR><BR>  * 5xx: Server Error - The server failed to fulfill an apparently <BR><BR>  valid request <BR><BR><BR>       | "100" ; Continue <BR><BR>       | "101" ; Switching Protocols <BR><BR>       | "200" ; OK <BR><BR>       | "201" ; Created <BR><BR>       | "202" ; Accepted <BR><BR>       | "203" ; Non-Authoritative Information <BR><BR>       | "204" ; No Content <BR><BR>       | "205" ; Reset Content <BR><BR>       | "206" ; Partial Content <BR><BR>       | "300" ; Multiple Choices <BR><BR>       | "301" ; Moved Permanently <BR><BR>       | "302" ; Moved Temporarily <BR><BR>       | "303" ; See Other <BR><BR>       | "304" ; Not Modified <BR><BR>       | "305" ; Use Proxy <BR><BR>       | "400" ; Bad Request <BR><BR>       | "401" ; Unauthorized <BR><BR>       | "402" ; Payment Required <BR><BR>       | "403" ; Forbidden <BR><BR>       | "404" ; Not Found <BR><BR>       | "405" ; Method Not Allowed <BR><BR>       | "406" ; Not Acceptable <BR><BR>       | "407" ; Proxy Authentication Required <BR><BR>       | "408" ; Request Time-out <BR><BR>       | "409" ; Conflict <BR><BR>       | "410" ; Gone <BR><BR>       | "411" ; Length Required <BR><BR>       | "412" ; Precondition Failed <BR><BR>       | "413" ; Request Entity Too Large <BR><BR>       | "414" ; Request-URI Too Large <BR><BR>       | "415" ; Unsupported Media Type <BR><BR>       | "500" ; Internal Server Error <BR><BR>       | "501" ; Not Implemented <BR><BR>       | "502" ; Bad Gateway <BR><BR>       | "503" ; Service Unavailable <BR><BR>       | "504" ; Gateway Time-out <BR><BR>       | "505" ; HTTP Version not supported <BR>

页: [1]



Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.