欢迎光临
我们一直在努力

PHP中如何使用header发送头部信息-PHP教程,PHP函数

建站超值云服务器,限时71元/月

在照彭武兴先生的《php bible》中所述,header可以送出status标头,如

header("status: 404 not found");

?>

就可以让用户浏览器出现文件找不到的404错误,但是我试了这样是不行的。

后来我到w3.org上查了http的相关资料,终于试出来了如何header出状态代码(status),与大家分享。

其实应该是这样的:

header("http/1.1 403 forbidden");

?>

第一部分为http协议的版本(http-version)

第二部分为状态代码(status)

第三部分为原因短语(reason-phrase)

三部分中间用一个空格分开,且中间不能有回车,第一部分和第二部分是必需的,第三部分则是给人看的,可写可不写甚至乱写。

还有,这一句的输出必须在html文件的第一行。

下面我给出各代码所代表的意思(是从w3.org上查到的,够权威了):

  * 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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » PHP中如何使用header发送头部信息-PHP教程,PHP函数
分享到: 更多 (0)

相关推荐

  • 暂无文章