cvs: phpdoc-zh /reference/http/functions headers-sent.xml

From: Date: Thu, 18 Aug 2005 04:35:10 +0000
Subject: cvs: phpdoc-zh /reference/http/functions headers-sent.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-2397@lists.php.net to get a copy of this message
lm92 Thu Aug 18 00:35:10 2005 EDT Modified files: /phpdoc-zh/reference/http/functions headers-sent.xml Log: updated to en version http://cvs.php.net/diff.php/phpdoc-zh/reference/http/functions/headers-sent.xml?r1=1.1&r2=1.2&ty=u Index: phpdoc-zh/reference/http/functions/headers-sent.xml diff -u phpdoc-zh/reference/http/functions/headers-sent.xml:1.1 phpdoc-zh/reference/http/functions/headers-sent.xml:1.2 --- phpdoc-zh/reference/http/functions/headers-sent.xml:1.1 Thu Jul 7 05:47:34 2005 +++ phpdoc-zh/reference/http/functions/headers-sent.xml Thu Aug 18 00:35:08 2005 @@ -1,37 +1,73 @@ -<?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> -<!-- $Author: yincheng $ --> -<!-- EN-Revision: 1.10 Maintainer: Avenger Status: ready --> -<!-- splitted from ./en/functions/http.xml, last change in rev 1.7 --> +<?xml version="1.0" encoding="gb2312"?> +<!-- $Revision: 1.2 $ --> +<!-- $Author: lm92 $ --> +<!-- EN-Revision: 1.16 Maintainer: Avenger Status: ready --> <refentry id="function.headers-sent"> <refnamediv> <refname>headers_sent</refname> - <refpurpose>²âÊÔÍ·²¿ÐÅÏ¢ÊÇ·ñÒѾ­±»·¢ËÍ£¬Èç¹ûÊÇ£¬·µ»Ø &true;</refpurpose> + <refpurpose>²âÊÔÍ·²¿ÐÅÏ¢ÊÇ·ñÒѾ­±»·¢ËÍ</refpurpose> </refnamediv> <refsect1> <title>ÃèÊö</title> <methodsynopsis> - <type>bool</type><methodname>headers_sent</methodname> - <methodparam><type>string</type><parameter>&amp;file</parameter></methodparam> - <methodparam choice="opt"><type>int</type><parameter>&amp;line</parameter></methodparam> + <type>bool</type><methodname>headers_sent</methodname> + <methodparam choice="opt"><type>string</type><parameter role="reference">file</parameter></methodparam> + <methodparam choice="opt"><type>int</type><parameter role="reference">line</parameter></methodparam> </methodsynopsis> <para> - Õâ¸öº¯Êý²âÊԽű¾ÖÐÍ·²¿ÐÅÏ¢ÊÇ·ñÒѾ­·¢ËÍ£¬Èç¹ûÊÇÔò·µ»Ø &true; ·ñÔò·µ»Ø &false;¡£Ò»µ©Í·²¿ÐÅÏ¢ÒѾ­±»·¢ËÍ£¬Ä㽫²»ÄÜÔÙʹÓà <function>header</function> - º¯ÊýÀ´·¢ËÍÆäËüµÄÍ·²¿ÐÅÏ¢¡£Ê¹Óô˺¯Êý¿ÉÒÔʹÄã×î´óÏ޶ȵıÜÃâÀàËÆ "Duplicate headers ..." µÄ´íÎóÐÅÏ¢¡£ + Èç¹û HTTP Í·²¿ÐÅÏ¢ÉÐδ±»·¢ËͳöÈ¥µÄ»°£¬<function>headers_sent</function> + ½«·µ»Ø &false;£¬·ñÔò·µ»Ø &true;¡£Ò»µ©Í·²¿ÐÅÏ¢ÒѾ­±»·¢ËÍ£¬Ä㽫²»ÄÜÔÙʹÓà + <function>header</function> º¯ÊýÀ´·¢ËÍÆäËüµÄÍ·²¿ÐÅÏ¢¡£Ê¹Óô˺¯Êý¿ÉÒÔʹÄã×î´óÏ޶ȵıÜÃâÀàËÆ + HTTP Í·²¿µÄ´íÎóÐÅÏ¢¡£ </para> <para> - Èç¹û¿ÉÏȲÎÊý <parameter>file</parameter> - ¼° <parameter>line</parameter> - ±»Ö¸¶¨£¬Ôòº¯Êý»á·µ»ØÖ¸¶¨ÎļþÖ¸¶¨ÐÐÊýÆðÍ·²¿ÐÅÏ¢µÄ·¢ËÍÇé¿ö¡£ + Èç¹ûÖ¸¶¨ÁË¿ÉÑ¡²ÎÊý <parameter>file</parameter> ºÍ + <parameter>line</parameter>£¬ <function>headers_sent</function> + Ôò»á°ÑÔÚ PHP µÄÎļþÃûÒÔ¼°¿ªÊ¼Êä³öÍ·²¿ÐÅÏ¢µÄÐÐÊý·µ»Øµ½ <parameter>file</parameter> + ºÍ <parameter>line</parameter> µÄ±äÁ¿ÖµÖС£ </para> <note> <simpara> - <parameter>file</parameter> and <parameter>line</parameter> - ²ÎÊýÔÚ PHP 4.3.0 °æ±¾Öб»¼ÓÈë¡£ + <parameter>file</parameter> ºÍ <parameter>line</parameter> + ²ÎÊýÊÇÔÚ PHP 4.3.0 °æ±¾ÖÐÌí¼ÓµÄ¡£ </simpara> </note> <para> - ¸ü¶àϸ½ÚµÄÌÖÂ۲μû <function>header</function>¡£ + <example> + <title><function>headers_sent</function> Àý×Ó</title> + <programlisting role="php"> +<![CDATA[ +<?php + +// Èç¹ûûÓз¢ËÍÍ·²¿ÐÅÏ¢µÄ»°£¬¾ÍÏò¿Í»§¶Ë·¢ËÍÒ»¸ö +if (!headers_sent()) { + header('Location: http://www.example.com/'); + exit; +} + +// Ò»¸öʹÓà file ºÍ line ²ÎÊýµÄÀý×Ó£¬Ö»ÄÜÔËÐÐÔÚ PHP 4.3.0 »òÒÔÉϰ汾 +// ×¢Òâ $filename ºÍ $linenum ¿ÉÒÔ´«µÝ¸øºóÐø´úÂëʹÓ㬲»Òª³õʼ»¯ËüÃÇ¡£ +if (!headers_sent($filename, $linenum)) { + header('Location: http://www.example.com/'); + exit; + +// ¿ÉÒÔÕâÑùÀ´´¥·¢Ò»¸ö´íÎó +} else { + + echo "Headers already sent in $filename on line $linenum\n" . + "Cannot redirect, for now please click this <a " . + "href=\"http://www.example.com\">link</a> instead\n"; + exit; +} + +?> +]]> + </programlisting> + </example> + </para> + <para> + ¸ü¶àϸ½ÚµÄÌÖÂ۲μû <function>ob_start</function>£¬<function>trigger_error</function> + ºÍ <function>header</function>¡£ </para> </refsect1> </refentry>

« previous php.doc.zh (#2397) next »