选择显示字体大小

php中如何header出状态代码 (转)


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

header(&quot;status: 404 not found&quot;);

?>

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

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

其实应该是这样的:

header(&quot;http/1.1 403 forbidden&quot;);

?>

第一部分为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


       &quot;100&quot; ; continue

       &quot;101&quot; ; switching protocols

       &quot;200&quot; ; ok

       &quot;201&quot; ; created

       &quot;202&quot; ; accepted

       &quot;203&quot; ; non-authoritative information

       &quot;204&quot; ; no content

       &quot;205&quot; ; reset content

       &quot;206&quot; ; partial content

       &quot;300&quot; ; multiple choices

       &quot;301&quot; ; moved permanently

       &quot;302&quot; ; moved temporarily

       &quot;303&quot; ; see other

       &quot;304&quot; ; not modified

       &quot;305&quot; ; use proxy

       &quot;400&quot; ; bad request

       &quot;401&quot; ; unauthorized

       &quot;402&quot; ; payment required

       &quot;403&quot; ; forbidden

       &quot;404&quot; ; not found

       &quot;405&quot; ; method not allowed

       &quot;406&quot; ; not acceptable

       &quot;407&quot; ; proxy authentication required

       &quot;408&quot; ; request time-out

       &quot;409&quot; ; conflict

       &quot;410&quot; ; gone

       &quot;411&quot; ; length required

       &quot;412&quot; ; precondition failed

       &quot;413&quot; ; request entity too large

       &quot;414&quot; ; request-uri too large

       &quot;415&quot; ; unsupported media type

       &quot;500&quot; ; internal server error

       &quot;501&quot; ; not implemented

       &quot;502&quot; ; bad gateway

       &quot;503&quot; ; service unavailable

       &quot;504&quot; ; gateway time-out

       &quot;505&quot; ; http version not supported


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons