动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 PHP中如何Header出状态代码

作者来源: 
阅读 数 474 人次 , 2006-3-29 4:07:00 


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

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

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:php在母语方面的支持
· 下一篇:中文注释的php.ini
· 引用文件
· 几种显示数据的方法的比较
· 计算两者相差几个月零几天
· Win9x/ME下Apache+PHP安装配置
· 两个PHP发送邮件的例子


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077