cvs: phpdoc-zh /reference/http functions.xml /reference/http/functions header.xml headers-sent.xml setcookie.xml
| From: | Xiao shengwen | Date: | Thu, 07 Jul 2005 09:47:34 +0000 |
| Subject: | cvs: phpdoc-zh /reference/http functions.xml /reference/http/functions header.xml headers-sent.xml setcookie.xml | ||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-2012@lists.php.net to get a copy of this message | ||
yincheng Thu Jul 7 05:47:34 2005 EDT
Added files:
/phpdoc-zh/reference/http/functions header.xml headers-sent.xml
setcookie.xml
Modified files:
/phpdoc-zh/reference/http functions.xml
Log:
½«function¸ÄΪÕýÈ·µÄfunctions
http://cvs.php.net/diff.php/phpdoc-zh/reference/http/functions.xml?r1=1.2&r2=1.3&ty=u Index: phpdoc-zh/reference/http/functions.xml diff -u /dev/null phpdoc-zh/reference/http/functions.xml:1.3 --- /dev/null Thu Jul 7 05:47:34 2005 +++ phpdoc-zh/reference/http/functions.xml Thu Jul 7 05:47:34 2005 @@ -0,0 +1,5 @@ +&reference.http.functions.header; +&reference.http.functions.headers-list; +&reference.http.functions.headers-sent; +&reference.http.functions.setcookie; +&reference.http.functions.setrawcookie; http://cvs.php.net/co.php/phpdoc-zh/reference/http/functions/header.xml?r=1.1&p=1 Index: phpdoc-zh/reference/http/functions/header.xml +++ phpdoc-zh/reference/http/functions/header.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <!-- $Author: yincheng $ --> <!-- EN-Revision: 1.8 Maintainer: Avenger Status: working --> <!-- splitted from ./en/functions/http.xml, last change in rev 1.2 --> <refentry id="function.header"> <refnamediv> <refname>header</refname> <refpurpose>Ïòä¯ÀÀÆ÷·¢ËÍÒ»¸ö HTTP Í·²¿ÐÅÏ¢</refpurpose> </refnamediv> <refsect1> <title>ÃèÊö</title> <methodsynopsis> <type>int</type><methodname>header</methodname> <methodparam><type>string</type><parameter>string</parameter></methodparam> <methodparam choice="opt"><type>bool</type><parameter>replace</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>http_reponse_code</parameter></methodparam> </methodsynopsis> <para> <function>header</function> º¯ÊýÓÃÀ´·¢ËÍÒ»¸ö <acronym>HTTP</acronym> Í·²¿ÐÅÏ¢µ½¿Í»§¶ËµÄä¯ÀÀÆ÷¡£ÓÐ¹Ø <acronym>HTTP</acronym> Í·²¿ÐÅÏ¢µÄ¸ü¶àÄÚÈݲμû¹Ù·½Îĵµ <ulink url="&spec.http1.1;">HTTP/1.1 specification</ulink>¡£ </para> <para> ¿ÉÑ¡²ÎÊý <parameter>replace</parameter> ÓÃÀ´±íʾµ±³öÏÖÁ½¸öÏàËÆµÄÍ·²¿ÐÅϢʱ£¬ÊÇÌæ»»Ç°Ò»¸öÏàͬµÄÍ·²¿ÐÅÏ¢»¹ÊÇÔö¼ÓÒ»¸öÏàͬµÄÍ·²¿ÐÅÏ¢¡£Ä¬ÈÏÎªÌæ»»£¬Èç¹ûÄ㽫ÆäÉèΪ &false; Ôò¿ÉÒÔ¶à´Î·¢ËÍÏàͬµÄÍ·²¿ÐÅÏ¢¡£ÀýÈç: <informalexample> <programlisting role="php"> <![CDATA[ <?php header('WWW-Authenticate: Negotiate'); header('WWW-Authenticate: NTLM', FALSE); ?> ]]> </programlisting> </informalexample> </para> <para> µÚ¶þ¸ö¿ÉÑ¡²ÎÊý <parameter>http_response_code</parameter> ±íʾ HTTP µÄÍ·²¿ÐÅÏ¢µÄ´úÂë¡£(´Ë²ÎÊýÔÚPHP 4.3.0 ±»¼ÓÈë¡£) </para> <para> Í·²¿ÐÅÏ¢µÄ¸ñʽÓÐÁ½ÖÖÐÎʽ¡£Ò»ÖÖÇé¿öÊÇÒÔ×Ö·û ¡°<literal>HTTP/</literal>¡± (²»Çø·Ö´óСд)¿ªÍ·µÄ£¬which will be used to figure out the HTTP status code to send¡£ÀýÈç,Èç¹ûÄãʹÓÃµÄ WEB ·þÎñÆ÷ÊÇ Apache µÄ»°£¬Èç¹ûÒªÖÆ×÷Ò»¸öÕÒ²»µ½ÎÄÕµĴíÎó´¦ÀíÒ³Ãæ (ʹÓà <literal>ErrorDocument</literal> Ö¸Áî)£¬Äã¿ÉÄÜ»áÐèÒªÓÃËüÀ´²úÉúһЩÊʵ±µÄ״̬´úÂë¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header("HTTP/1.0 404 Not Found"); ?> ]]> </programlisting> </informalexample> <note> <para> HTTP Í·²¿ÐÅϢͨ³£ÊÇÊ×Ïȱ»·¢Ë͵½¿Í»§¶ËµÄ£¬Ëü²¢²»¹ÜÄãµÄ <function>header</function> º¯ÊýÊÇ·ñÊÇÔÚµÚÒ»ÐС£ÔÚͨ³£µÄÇé¿öÏÂThe status may be overridden by calling <function>header</function> with a new status line at any time unless the HTTP headers have already been sent. ³ý·Ç HTTP Í·²¿ÐÅÏ¢ÒѾ±»·¢ËÍ¡£ </para> </note> <note> <para> ÔÚ PHP 3 ÖУ¬´Ëº¯ÊýÖ»ÔÚ PHP ÒÔ Apache µÄÄ£¿é»¯ÔËÐеÄʱºòÓÐЧ¡£Äã¿ÉÒÔʹÓà <literal>Status</literal> À´´ïµ½ÏàͬµÄЧ¹û¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header("Status: 404 Not Found"); ?> ]]> </programlisting> </informalexample> </para> </note> </para> <para> µÚ¶þÖÖÌØÊâÇé¿öÊÇÒÔ "Location:" ¿ªÍ·µÄÐÅÏ¢¡£Ëü²»Ö»ÊǼòµ¥µÄÏòä¯ÀÀÆ÷·¢ËÍһЩͷ²¿ÐÅÏ¢£¬Í¨³£Ëü»áÏòä¯ÀÀÆ÷·¢ËͳöÒ»¸ö <literal>REDIRECT</literal> (302) (Ìø×ª) ״̬´úÂ룬³ý·ÇһЩÀàËÆÓÚ <literal>3xx</literal> µÄ״̬´úÂëÒѾ±»·¢ËÍ¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header("Location: http://www.example.com/"); /* Redirect browser */ exit; /* Make sure that code below does not get executed when we redirect. */ ?> ]]> </programlisting> </informalexample> </para> <note> <para> HTTP/1.1 ±ê×¼ÐèÒªÒ»¸ö¾ø¶ÔµØÖ·µÄ <acronym>URI</acronym> ×öΪ <ulink url="&spec.http1.1;-sec14.html#sec14.30">Location:</ulink> µÄ²ÎÊý, µ«ÓÐһЩ¿Í»§¶ËÖ§³ÖÐéÄâµÄ·¾¶¡£Äãͨ³£¿ÉÒÔʹÓà <literal>$_SERVER['HTTP_HOST']</literal>¡¢<literal>$_SERVER['PHP_SELF']</literal> ¼° <function>dirname</function> º¯ÊýÀ´×Ô¼º»ñÈ¡ËùÐèÒªµÄ¾ø¶Ô·¾¶: <informalexample> <programlisting> <![CDATA[ <?php header("Location: http://".$_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF']) ."/".$relative_url); ?> ]]> </programlisting> </informalexample> </para> </note> <para> PHP ½Å±¾Í¨³£ÊǶ¯Ì¬¸Ä±äµÄ¡£¿ÉÓÐЩ¿Í»§¶Ë»òһЩ´úÀí·þÎñÆ÷»á°ÑһЩä¯ÀÀ¹ýµÄÄÚÈݸø»º³åÆðÀ´£¬ÕâÑùÄú¸üеĽű¾¾Í²»Äܱ»¿Í»§¶Ë¼°Ê±µÄ·¢ÏÖ£¬Äã¿ÉÒÔͨ¹ý·¢ËÍһЩÀàËÆÏÂÃæÀý×ÓÖеÄÍ·²¿ÐÅÏ¢À´½ûÖ¹ËûÃÇ»º´æÄãµÄÍøÒ³¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 ?> ]]> </programlisting> </informalexample> <note> <para> Äã¿ÉÄܻᷢÏÖ¼´Ê¹ÄãûÓаÑÉϱߵĴúÂëÈ«²¿Êä³öÄãµÄÍøÒ³Ò²Ã»Óб»»º³åÆðÀ´¡£ÕâÊÇÒòΪһЩÓû§ÔÚËûÃǵÄä¯ÀÀÆ÷µÄһЩѡÏîÉèÖÃÖÐÉèÖÃÁ˽ûÖ¹»º´æÎļþµÄÑ¡Ïî¡£ </para> <para> ÁíÍ⣬µ± session ÔÚ´úÂëÖб»Ê¹ÓÃʱ£¬ÀûÓà <function>session_cache_limiter</function> º¯ÊýºÍ <literal>session.cache_limiter</literal> Ñ¡Ïî¿ÉÒÔ×Ô¶¯µÄ²úÉúÏà¹ØµÄ»º³åÇø¡£ </para> </note> </para> <para> ÒªÀÎ¼Ç <function>header</function> ҪʹÓÃÔÚÈκÎÍøÒ³Êä³öǰ¡£°üÀ¨Ò»Ð©·Ç HTML ±êÇ©ºÍ¿ÕÐж¼²»ÔÊÐíÔÚÆä֮ǰÊä³ö¡£ÔÚʹÓà <function>include</function> ¡¢<function>require</function> º¯Êý»òһЩÆäËüµÄÎļþ´æÈ¡ÀຯÊýʱ£¬ÕâÊÇÒ»¸öºÜ³£·¸µÄ´íÎó¡£Í¬ÑùÔÚÒ»¸öµ¥¶ÀµÄ PHP/HTML ÎļþÖÐÕâ¸ö´íÎóÒ²ºÜÆÕ±é¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header ("Content-type: audio/x-pn-realaudio"); ?> // ³ö´í£¬×¢Òâ header ǰµÄ¿Õ¸ñ ]]> </programlisting> </informalexample> <note> <para> ÔÚ PHP 4ÀÄã¿ÉÒÔͨ¹ýһЩÊä³ö»º³åº¯ÊýÀ´½â¾öÕâ¸öÎÊÌâ¡£ÕâÑù×ö£¬Äã¿ÉÒÔ°ÑËùÓеÄÊä³ö¶¼»º³åµ½·þÎñ£¬Ö±µ½ÄãÏÂÃüÁî·¢ËÍËüÃÇ¡£Äã¿ÉÒÔÔÚÄãµÄ´úÂëÖÐʹÓà <function>ob_start</function> ¼° <function>ob_end_flush</function> À´ÊµÏÖÕâÑùµÄ¹¦ÄÜ£¬»òÕßͨ¹ýÐÞ¸ÄÄãµÄ &php.ini; ÖÐµÄ <literal>output_buffering</literal> Ñ¡ÏîÀ´ÊµÏÖ£¬Ò²¿ÉÒÔͨ¹ýÐÞ¸ÄÄãµÄ·þÎñÆ÷ÅäÖÃÎļþÀ´ÊµÏÖ¡£ </para> </note> </para> <para> Èç¹ûÄãÏëÌáʾÓû§ÏÂÔØ²¢±£´æÒ»¸öÎļþ£¬ÀýÈçÒ»¸ö PDF Îļþ£¬Äã¿ÉÒÔͨ¹ý·¢ËÍ <ulink url="&url.rfc2183;">Content-Disposition</ulink> ÐÅÏ¢À´Ê¹¿Í»§¶Ë»úÆ÷µ¯³öÏÂÔØ¶Ô»°¿òÀ´ÏÂÔØÄúÐèÒª´¦ÀíµÄÎļþ¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php // ÕâÑù½«»áÖ±½ÓÊä³öÒ»¸ö PDF Îļþ header("Content-type: application/pdf"); // ÕâÑù×ö¾Í»áÌáʾÏÂÔØ PDF Îļþ downloaded.pdf header("Content-Disposition: attachment; filename=downloaded.pdf"); // ÕâÊÇ original.pdf µÄÔ´Îļþ readfile('original.pdf'); ?> ]]> </programlisting> </informalexample> <note> <para> Microsoft Internet Explorer 4.01 ÖеÄÒ»¸ö©¶´Ê¹µÃ¸Ã»úÖÆÎÞ·¨Õý³£¹¤×÷¡£ÔÚ Microsoft Internet Explorer 5 ÖÐÕâ¸ö©¶´ÒÀÈ»´æÔÚ£¬Éý¼¶ Service Pack 2 ¼°ÆäÒÔºó°æ±¾ÖÐÕâ¸ö©¶´½«²»¸´´æÔÚ¡£ </para> </note> </para> <note> <simpara> Èç¹û PHP ÔËÐÐÔÚ°²È«Ä£Ê½ (<link linkend="ini.safe-mode">safe mode</link>) Ï£¬µ±Ç°Ê¹ÓÃÕߵıêʶºÅ (UID) »á¸½¼Óµ½Í·²¿ÐÅÏ¢ <literal>WWW-Authenticate</literal> µÄ <literal>realm</literal> ²¿·ÖÒ»Æð·¢ËÍ¡£(¿ÉÒÔÓÃÀ´×ö HTTP ÈÏÖ¤)¡£ </simpara> </note> <para> ²Î¼û <function>headers_sent</function>, <function>setcookie</function> ¼° <link linkend="features.http-auth">HTTP authentication</link> Õ½Ú. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/phpdoc-zh/reference/http/functions/headers-sent.xml?r=1.1&p=1 Index: phpdoc-zh/reference/http/functions/headers-sent.xml +++ phpdoc-zh/reference/http/functions/headers-sent.xml <?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 --> <refentry id="function.headers-sent"> <refnamediv> <refname>headers_sent</refname> <refpurpose>²âÊÔÍ·²¿ÐÅÏ¢ÊÇ·ñÒѾ±»·¢ËÍ£¬Èç¹ûÊÇ£¬·µ»Ø &true;</refpurpose> </refnamediv> <refsect1> <title>ÃèÊö</title> <methodsynopsis> <type>bool</type><methodname>headers_sent</methodname> <methodparam><type>string</type><parameter>&file</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>&line</parameter></methodparam> </methodsynopsis> <para> Õâ¸öº¯Êý²âÊԽű¾ÖÐÍ·²¿ÐÅÏ¢ÊÇ·ñÒѾ·¢ËÍ£¬Èç¹ûÊÇÔò·µ»Ø &true; ·ñÔò·µ»Ø &false;¡£Ò»µ©Í·²¿ÐÅÏ¢ÒѾ±»·¢ËÍ£¬Ä㽫²»ÄÜÔÙʹÓà <function>header</function> º¯ÊýÀ´·¢ËÍÆäËüµÄÍ·²¿ÐÅÏ¢¡£Ê¹Óô˺¯Êý¿ÉÒÔʹÄã×î´óÏ޶ȵıÜÃâÀàËÆ "Duplicate headers ..." µÄ´íÎóÐÅÏ¢¡£ </para> <para> Èç¹û¿ÉÏȲÎÊý <parameter>file</parameter> ¼° <parameter>line</parameter> ±»Ö¸¶¨£¬Ôòº¯Êý»á·µ»ØÖ¸¶¨ÎļþÖ¸¶¨ÐÐÊýÆðÍ·²¿ÐÅÏ¢µÄ·¢ËÍÇé¿ö¡£ </para> <note> <simpara> <parameter>file</parameter> and <parameter>line</parameter> ²ÎÊýÔÚ PHP 4.3.0 °æ±¾Öб»¼ÓÈë¡£ </simpara> </note> <para> ¸ü¶àϸ½ÚµÄÌÖÂ۲μû <function>header</function>¡£ </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/phpdoc-zh/reference/http/functions/setcookie.xml?r=1.1&p=1 Index: phpdoc-zh/reference/http/functions/setcookie.xml +++ phpdoc-zh/reference/http/functions/setcookie.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <!-- $Author: yincheng $ --> <!-- EN-Revision: 1.12 Maintainer: Avenger Status: ready --> <!-- splitted from ./en/functions/http.xml, last change in rev 1.2 --> <refentry id="function.setcookie"> <refnamediv> <refname>setcookie</refname> <refpurpose>·¢ËÍÒ»¸ö cookie ÐÅÏ¢</refpurpose> </refnamediv> <refsect1> <title>ÃèÊö</title> <methodsynopsis> <type>boolean</type><methodname>setcookie</methodname> <methodparam><type>string</type><parameter>name</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>value</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>expire</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>path</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>domain</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>secure</parameter></methodparam> </methodsynopsis> <para> <function>setcookie</function> º¯ÊýÓÃÀ´½¨Á¢Ò»¸öÐ嵀 cookie µÄÐÅÏ¢¡£ºÍÆäËüÍ·²¿ÐÅÏ¢Ò»Ñù£¬cookies ±ØÐëÒªÊä³öÔÚÎļþµÄ<emphasis>×îÇ°Ãæ</emphasis>£¬Ò²¾ÍÒâζ×ÅÔÚÆä֮ǰ£¬Äã²»ÄÜÊä³öÈκÎ×Ö·û (ÕâÊǹ涨)¡£°üÀ¨ <literal><html></literal> ºÍ <literal><head></literal> ±êÇ©ÒÔ¼°Ò»Ð©¿Õ¸ñ¡£Èç¹ûÕâЩ±êÇ©ÔÚʹÓà <function>setcookie</function> º¯ÊýǰÊä³ö£¬º¯ÊýÔËÐÐÔò»áʧ°Ü²¢·µ»Ø &false;¡£ Ö»Òª <function>setcookie</function> º¯Êý³É¹¦ÔËÐУ¬²»¹Ü¸ÃÐÅÏ¢ÊÇ·ñ±»Óû§½ÓÊÜ£¬¶¼»á·µ»Ø &true;¡£ </para> <para> ³ýÁË <parameter>name</parameter> ÒÔÍ⣬ÆäËüËùÓвÎÊý¶¼ÊÇ¿ÉÑ¡µÄ¡£Èç¹ûÖ»ÓÐ name ²ÎÊý£¬Õ⽫»áɾ³ý¿Í»§¶ËÃû³ÆÎª name µÄ cookie¡£µ±È»£¬ÎªÁËÌø¹ýijЩ²ÎÊýµÄÉ趨£¬Äã¿ÉÒÔΪһЩ²ÎÊý¸³¿Õ×Ö·û (<emphasis>""</emphasis>)¡£µ«²ÎÊý <parameter>expire</parameter> ¼° <parameter>secure</parameter> µÄÀàÐÍÓ¦¸ÃΪÕûÊý (integers) ²¢ÇÒ²»Äܱ»¸³Îª¿Õ×Ö·û¡£Äã¿ÉÒÔÓà 0 À´´úÌæ(<emphasis>0</emphasis>)¡£²ÎÊý <parameter>expire</parameter> ÊÇÒ»¸ö Unix µÄʱ¼ä´Á£¬¿ÉÒÔÓà <function>time</function> »ò <function>mktime</function> º¯ÊýÀ´»ñµÃ¡£<parameter>secure</parameter> ²ÎÊý±íÃ÷¸Ã cookie Ö»ÔÚ°²È« HTTP Á¬½Óϲű»·¢ËÍ¡£ </para> <para> µ± cookies ±»ÉèÖú󣬱ã¿ÉÒÔÔÚÆäËüÒ³ÃæÍ¨¹ý <link linkend="reserved.variables.cookies">$_COOKIE</link> »ò <varname>$HTTP_COOKIE_VARS</varname> Êý×éÈ¡µÃÆäÖµ¡£ÐèҪעÒâµÄÊÇ£¬<link linkend="language.variables.superglobals">autoglobals</link> µÄ <varname>$_COOKIE</varname> ÐÎʽÊÊÓÃÓÚ PHP <ulink url="&url.php.release4.1.0;">4.1.0</ulink> »ò¸ü¸ß°æ±¾¡£¶ø <varname>$HTTP_COOKIE_VARS</varname> Ôò´Ó PHP 3 Æð¾Í¿ÉÒÔʹÓÃ. </para> <para> ÐèҪעÒâµÄ¼¸µã: <itemizedlist> <listitem> <simpara> Cookies ²»»áÔÚÄãÉèÖÃËüµÄ±¾Ò³ÉúЧ¡¢Òª²âÊÔÒ»¸ö cookie ÊÇ·ñ±»³É¹¦µÄÉ趨£¬Äã¿ÉÒÔÔÚÆäµ½ÆÚ֮ǰͨ¹ýÁíÍâÒ»¸öÒ³ÃæÀ´·ÃÎÊÆäÖµ¡£¹ýÆÚʱ¼äÊÇͨ¹ý²ÎÊý <parameter>expire</parameter> À´ÉèÖõġ£ </simpara> </listitem> <listitem> <simpara> Cookies ½«»á±»ÓëÆäͬÃûµÄºóÉ趨µÄ cookie Ëù¸²¸Ç¡£ </simpara> </listitem> <listitem> <simpara> ÔÚʵ¼ÊÔËÓÃÖУ¬Äã¿ÉÒÔ°Ñ Cookies µÄÃû³ÆÉèÖóÉÒ»¸öÊý×飬µ«ÊÇÊý×é cookie ÖеÄÿ¸öÔªËØµÄÖµ½«»á±»µ¥¶À±£´æÔÚÓû§µÄϵͳÖС£Äã¿ÉÒÔÊÔ×ÅÓÃ<function>explode</function> »ò <function>serialize</function> º¯ÊýÀ´°Ñ¶à¸ö cookie ֵдÈëµ½Ò»¸ö cookie ÎļþÖС£ </simpara> </listitem> </itemizedlist> </para> <simpara> ÔÚ PHP 3 ÖУ¬ÔÚͬһ¸ö PHP ½Å±¾Öжà´ÎʹÓà <function>setcookie</function> À´ÉèÖà cookie£¬½«»á°´ÕÕµ¹ÐòµÄ·½Ê½À´·Ö±ðÖ´ÐУ¬Èç¹ûÄãÏëÒªÔÚ²åÈëÁíÍâÒ»¸ö cookie ǰɾ³ýÒ»¸ö cookie,Äã±ØÐëÏȲåÈëÈ»ºóÔÙɾ³ý¡£ÔÚ PHP 4 À¶à´Îµ÷Óà <function>setcookie</function> ÔòÊǰ´ÕÕ˳ÐòÀ´Ö´Ðеġ£ </simpara> <para> ÏÂÃæÒ»Ð©Àý×Ó˵Ã÷ÁËÈçºÎ·¢ËÍ cookies: <example> <title><function>setcookie</function> sent examples</title> <programlisting role="php"> <![CDATA[ setcookie ("TestCookie", $value); setcookie ("TestCookie", $value,time()+3600); /* expire in 1 hour */ setcookie ("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1); ]]> </programlisting> </example> </para> <para> Ò»¸ö¹ýÆÚµÄ cookie ½«»á±»×Ô¶¯É¾³ý¡£Àý×Ó˵Ã÷ÁËÈçºÎɾ³ýÒ»¸ö cookies: <example> <title><function>setcookie</function> delete examples</title> <programlisting role="php"> <![CDATA[ // set the expiration date to one hour ago setcookie ("TestCookie", "", time() - 3600); setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1); ]]> </programlisting> </example> </para> <para> ҪעÒâµÄÊÇ cookie µÄÖµÔÚ·¢Ë͵Äʱºò»á±»×Ô¶¯µÄ±àÂë²¢±£´æ£¬¶øµ±Äã¶ÁÈ¡ËüµÄʱºò£¬ËüÓֻᱻ×Ô¶¯µÄ½âÂë²¢×Ô¶¯°Ñ×Ô¼º¸³Öµ¸øÓë×Ô¼ºÍ¬ÃûµÄÒ»¸ö±äÁ¿¡£Äã¿ÉÒÔͨ¹ýÏÂÃæ¼òµ¥µÄÀý×ÓÀ´¿´µ½: <informalexample> <programlisting role="php"> <![CDATA[ echo $TestCookie; echo $_COOKIE["TestCookie"]; ]]> </programlisting> </informalexample> </para> <para> ÄãÒ²¿ÉÒÔÉèÖÃÒ»¸öÊý×éÀ´´æ·Å cookie£¬°ÑÐí¶àÃû³Æ²»Í¬µÄ cookie ·Åµ½Ò»¸öÊý×éÖдæ·Å¡£ÕâÑùÄãÔÚ½ÓÊÕ cookie µÄʱºòÖ»ÐèÒªÒª»ñȡһ¸öÊý×é: <informalexample> <programlisting role="php"> <![CDATA[ setcookie ("cookie[three]", "cookiethree"); setcookie ("cookie[two]", "cookietwo"); setcookie ("cookie[one]", "cookieone"); if (isset ($cookie)) { while (list ($name, $value) = each ($cookie)) { echo "$name == $value<br>\n"; } } ]]> </programlisting> </informalexample> </para> <para> ¹ØÓÚ cookies ¸ü¶àµÄ½éÉÜ£¬¿ÉÒԲο¼Íø¾°¹«Ë¾µÄ cookies ˵Ã÷Êé <ulink url="&spec.cookies;">&spec.cookies;</ulink>. </para> <simpara> Netscape Communicator 4.05 ¼° Microsoft Internet Explorer 3.x ÔÚ cookie µÄ·¾¶ºÍʱ¼äûÓÐÉèÖõÄÇé¿öÏ»á³öÏÖһЩÎÊÌâ¡£ </simpara> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
http://cvs.php.net/diff.php/phpdoc-zh/reference/http/functions.xml?r1=1.2&r2=1.3&ty=u Index: phpdoc-zh/reference/http/functions.xml diff -u /dev/null phpdoc-zh/reference/http/functions.xml:1.3 --- /dev/null Thu Jul 7 05:47:34 2005 +++ phpdoc-zh/reference/http/functions.xml Thu Jul 7 05:47:34 2005 @@ -0,0 +1,5 @@ +&reference.http.functions.header; +&reference.http.functions.headers-list; +&reference.http.functions.headers-sent; +&reference.http.functions.setcookie; +&reference.http.functions.setrawcookie; http://cvs.php.net/co.php/phpdoc-zh/reference/http/functions/header.xml?r=1.1&p=1 Index: phpdoc-zh/reference/http/functions/header.xml +++ phpdoc-zh/reference/http/functions/header.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <!-- $Author: yincheng $ --> <!-- EN-Revision: 1.8 Maintainer: Avenger Status: working --> <!-- splitted from ./en/functions/http.xml, last change in rev 1.2 --> <refentry id="function.header"> <refnamediv> <refname>header</refname> <refpurpose>Ïòä¯ÀÀÆ÷·¢ËÍÒ»¸ö HTTP Í·²¿ÐÅÏ¢</refpurpose> </refnamediv> <refsect1> <title>ÃèÊö</title> <methodsynopsis> <type>int</type><methodname>header</methodname> <methodparam><type>string</type><parameter>string</parameter></methodparam> <methodparam choice="opt"><type>bool</type><parameter>replace</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>http_reponse_code</parameter></methodparam> </methodsynopsis> <para> <function>header</function> º¯ÊýÓÃÀ´·¢ËÍÒ»¸ö <acronym>HTTP</acronym> Í·²¿ÐÅÏ¢µ½¿Í»§¶ËµÄä¯ÀÀÆ÷¡£ÓÐ¹Ø <acronym>HTTP</acronym> Í·²¿ÐÅÏ¢µÄ¸ü¶àÄÚÈݲμû¹Ù·½Îĵµ <ulink url="&spec.http1.1;">HTTP/1.1 specification</ulink>¡£ </para> <para> ¿ÉÑ¡²ÎÊý <parameter>replace</parameter> ÓÃÀ´±íʾµ±³öÏÖÁ½¸öÏàËÆµÄÍ·²¿ÐÅϢʱ£¬ÊÇÌæ»»Ç°Ò»¸öÏàͬµÄÍ·²¿ÐÅÏ¢»¹ÊÇÔö¼ÓÒ»¸öÏàͬµÄÍ·²¿ÐÅÏ¢¡£Ä¬ÈÏÎªÌæ»»£¬Èç¹ûÄ㽫ÆäÉèΪ &false; Ôò¿ÉÒÔ¶à´Î·¢ËÍÏàͬµÄÍ·²¿ÐÅÏ¢¡£ÀýÈç: <informalexample> <programlisting role="php"> <![CDATA[ <?php header('WWW-Authenticate: Negotiate'); header('WWW-Authenticate: NTLM', FALSE); ?> ]]> </programlisting> </informalexample> </para> <para> µÚ¶þ¸ö¿ÉÑ¡²ÎÊý <parameter>http_response_code</parameter> ±íʾ HTTP µÄÍ·²¿ÐÅÏ¢µÄ´úÂë¡£(´Ë²ÎÊýÔÚPHP 4.3.0 ±»¼ÓÈë¡£) </para> <para> Í·²¿ÐÅÏ¢µÄ¸ñʽÓÐÁ½ÖÖÐÎʽ¡£Ò»ÖÖÇé¿öÊÇÒÔ×Ö·û ¡°<literal>HTTP/</literal>¡± (²»Çø·Ö´óСд)¿ªÍ·µÄ£¬which will be used to figure out the HTTP status code to send¡£ÀýÈç,Èç¹ûÄãʹÓÃµÄ WEB ·þÎñÆ÷ÊÇ Apache µÄ»°£¬Èç¹ûÒªÖÆ×÷Ò»¸öÕÒ²»µ½ÎÄÕµĴíÎó´¦ÀíÒ³Ãæ (ʹÓà <literal>ErrorDocument</literal> Ö¸Áî)£¬Äã¿ÉÄÜ»áÐèÒªÓÃËüÀ´²úÉúһЩÊʵ±µÄ״̬´úÂë¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header("HTTP/1.0 404 Not Found"); ?> ]]> </programlisting> </informalexample> <note> <para> HTTP Í·²¿ÐÅϢͨ³£ÊÇÊ×Ïȱ»·¢Ë͵½¿Í»§¶ËµÄ£¬Ëü²¢²»¹ÜÄãµÄ <function>header</function> º¯ÊýÊÇ·ñÊÇÔÚµÚÒ»ÐС£ÔÚͨ³£µÄÇé¿öÏÂThe status may be overridden by calling <function>header</function> with a new status line at any time unless the HTTP headers have already been sent. ³ý·Ç HTTP Í·²¿ÐÅÏ¢ÒѾ±»·¢ËÍ¡£ </para> </note> <note> <para> ÔÚ PHP 3 ÖУ¬´Ëº¯ÊýÖ»ÔÚ PHP ÒÔ Apache µÄÄ£¿é»¯ÔËÐеÄʱºòÓÐЧ¡£Äã¿ÉÒÔʹÓà <literal>Status</literal> À´´ïµ½ÏàͬµÄЧ¹û¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header("Status: 404 Not Found"); ?> ]]> </programlisting> </informalexample> </para> </note> </para> <para> µÚ¶þÖÖÌØÊâÇé¿öÊÇÒÔ "Location:" ¿ªÍ·µÄÐÅÏ¢¡£Ëü²»Ö»ÊǼòµ¥µÄÏòä¯ÀÀÆ÷·¢ËÍһЩͷ²¿ÐÅÏ¢£¬Í¨³£Ëü»áÏòä¯ÀÀÆ÷·¢ËͳöÒ»¸ö <literal>REDIRECT</literal> (302) (Ìø×ª) ״̬´úÂ룬³ý·ÇһЩÀàËÆÓÚ <literal>3xx</literal> µÄ״̬´úÂëÒѾ±»·¢ËÍ¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header("Location: http://www.example.com/"); /* Redirect browser */ exit; /* Make sure that code below does not get executed when we redirect. */ ?> ]]> </programlisting> </informalexample> </para> <note> <para> HTTP/1.1 ±ê×¼ÐèÒªÒ»¸ö¾ø¶ÔµØÖ·µÄ <acronym>URI</acronym> ×öΪ <ulink url="&spec.http1.1;-sec14.html#sec14.30">Location:</ulink> µÄ²ÎÊý, µ«ÓÐһЩ¿Í»§¶ËÖ§³ÖÐéÄâµÄ·¾¶¡£Äãͨ³£¿ÉÒÔʹÓà <literal>$_SERVER['HTTP_HOST']</literal>¡¢<literal>$_SERVER['PHP_SELF']</literal> ¼° <function>dirname</function> º¯ÊýÀ´×Ô¼º»ñÈ¡ËùÐèÒªµÄ¾ø¶Ô·¾¶: <informalexample> <programlisting> <![CDATA[ <?php header("Location: http://".$_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF']) ."/".$relative_url); ?> ]]> </programlisting> </informalexample> </para> </note> <para> PHP ½Å±¾Í¨³£ÊǶ¯Ì¬¸Ä±äµÄ¡£¿ÉÓÐЩ¿Í»§¶Ë»òһЩ´úÀí·þÎñÆ÷»á°ÑһЩä¯ÀÀ¹ýµÄÄÚÈݸø»º³åÆðÀ´£¬ÕâÑùÄú¸üеĽű¾¾Í²»Äܱ»¿Í»§¶Ë¼°Ê±µÄ·¢ÏÖ£¬Äã¿ÉÒÔͨ¹ý·¢ËÍһЩÀàËÆÏÂÃæÀý×ÓÖеÄÍ·²¿ÐÅÏ¢À´½ûÖ¹ËûÃÇ»º´æÄãµÄÍøÒ³¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 ?> ]]> </programlisting> </informalexample> <note> <para> Äã¿ÉÄܻᷢÏÖ¼´Ê¹ÄãûÓаÑÉϱߵĴúÂëÈ«²¿Êä³öÄãµÄÍøÒ³Ò²Ã»Óб»»º³åÆðÀ´¡£ÕâÊÇÒòΪһЩÓû§ÔÚËûÃǵÄä¯ÀÀÆ÷µÄһЩѡÏîÉèÖÃÖÐÉèÖÃÁ˽ûÖ¹»º´æÎļþµÄÑ¡Ïî¡£ </para> <para> ÁíÍ⣬µ± session ÔÚ´úÂëÖб»Ê¹ÓÃʱ£¬ÀûÓà <function>session_cache_limiter</function> º¯ÊýºÍ <literal>session.cache_limiter</literal> Ñ¡Ïî¿ÉÒÔ×Ô¶¯µÄ²úÉúÏà¹ØµÄ»º³åÇø¡£ </para> </note> </para> <para> ÒªÀÎ¼Ç <function>header</function> ҪʹÓÃÔÚÈκÎÍøÒ³Êä³öǰ¡£°üÀ¨Ò»Ð©·Ç HTML ±êÇ©ºÍ¿ÕÐж¼²»ÔÊÐíÔÚÆä֮ǰÊä³ö¡£ÔÚʹÓà <function>include</function> ¡¢<function>require</function> º¯Êý»òһЩÆäËüµÄÎļþ´æÈ¡ÀຯÊýʱ£¬ÕâÊÇÒ»¸öºÜ³£·¸µÄ´íÎó¡£Í¬ÑùÔÚÒ»¸öµ¥¶ÀµÄ PHP/HTML ÎļþÖÐÕâ¸ö´íÎóÒ²ºÜÆÕ±é¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php header ("Content-type: audio/x-pn-realaudio"); ?> // ³ö´í£¬×¢Òâ header ǰµÄ¿Õ¸ñ ]]> </programlisting> </informalexample> <note> <para> ÔÚ PHP 4ÀÄã¿ÉÒÔͨ¹ýһЩÊä³ö»º³åº¯ÊýÀ´½â¾öÕâ¸öÎÊÌâ¡£ÕâÑù×ö£¬Äã¿ÉÒÔ°ÑËùÓеÄÊä³ö¶¼»º³åµ½·þÎñ£¬Ö±µ½ÄãÏÂÃüÁî·¢ËÍËüÃÇ¡£Äã¿ÉÒÔÔÚÄãµÄ´úÂëÖÐʹÓà <function>ob_start</function> ¼° <function>ob_end_flush</function> À´ÊµÏÖÕâÑùµÄ¹¦ÄÜ£¬»òÕßͨ¹ýÐÞ¸ÄÄãµÄ &php.ini; ÖÐµÄ <literal>output_buffering</literal> Ñ¡ÏîÀ´ÊµÏÖ£¬Ò²¿ÉÒÔͨ¹ýÐÞ¸ÄÄãµÄ·þÎñÆ÷ÅäÖÃÎļþÀ´ÊµÏÖ¡£ </para> </note> </para> <para> Èç¹ûÄãÏëÌáʾÓû§ÏÂÔØ²¢±£´æÒ»¸öÎļþ£¬ÀýÈçÒ»¸ö PDF Îļþ£¬Äã¿ÉÒÔͨ¹ý·¢ËÍ <ulink url="&url.rfc2183;">Content-Disposition</ulink> ÐÅÏ¢À´Ê¹¿Í»§¶Ë»úÆ÷µ¯³öÏÂÔØ¶Ô»°¿òÀ´ÏÂÔØÄúÐèÒª´¦ÀíµÄÎļþ¡£ <informalexample> <programlisting role="php"> <![CDATA[ <?php // ÕâÑù½«»áÖ±½ÓÊä³öÒ»¸ö PDF Îļþ header("Content-type: application/pdf"); // ÕâÑù×ö¾Í»áÌáʾÏÂÔØ PDF Îļþ downloaded.pdf header("Content-Disposition: attachment; filename=downloaded.pdf"); // ÕâÊÇ original.pdf µÄÔ´Îļþ readfile('original.pdf'); ?> ]]> </programlisting> </informalexample> <note> <para> Microsoft Internet Explorer 4.01 ÖеÄÒ»¸ö©¶´Ê¹µÃ¸Ã»úÖÆÎÞ·¨Õý³£¹¤×÷¡£ÔÚ Microsoft Internet Explorer 5 ÖÐÕâ¸ö©¶´ÒÀÈ»´æÔÚ£¬Éý¼¶ Service Pack 2 ¼°ÆäÒÔºó°æ±¾ÖÐÕâ¸ö©¶´½«²»¸´´æÔÚ¡£ </para> </note> </para> <note> <simpara> Èç¹û PHP ÔËÐÐÔÚ°²È«Ä£Ê½ (<link linkend="ini.safe-mode">safe mode</link>) Ï£¬µ±Ç°Ê¹ÓÃÕߵıêʶºÅ (UID) »á¸½¼Óµ½Í·²¿ÐÅÏ¢ <literal>WWW-Authenticate</literal> µÄ <literal>realm</literal> ²¿·ÖÒ»Æð·¢ËÍ¡£(¿ÉÒÔÓÃÀ´×ö HTTP ÈÏÖ¤)¡£ </simpara> </note> <para> ²Î¼û <function>headers_sent</function>, <function>setcookie</function> ¼° <link linkend="features.http-auth">HTTP authentication</link> Õ½Ú. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/phpdoc-zh/reference/http/functions/headers-sent.xml?r=1.1&p=1 Index: phpdoc-zh/reference/http/functions/headers-sent.xml +++ phpdoc-zh/reference/http/functions/headers-sent.xml <?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 --> <refentry id="function.headers-sent"> <refnamediv> <refname>headers_sent</refname> <refpurpose>²âÊÔÍ·²¿ÐÅÏ¢ÊÇ·ñÒѾ±»·¢ËÍ£¬Èç¹ûÊÇ£¬·µ»Ø &true;</refpurpose> </refnamediv> <refsect1> <title>ÃèÊö</title> <methodsynopsis> <type>bool</type><methodname>headers_sent</methodname> <methodparam><type>string</type><parameter>&file</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>&line</parameter></methodparam> </methodsynopsis> <para> Õâ¸öº¯Êý²âÊԽű¾ÖÐÍ·²¿ÐÅÏ¢ÊÇ·ñÒѾ·¢ËÍ£¬Èç¹ûÊÇÔò·µ»Ø &true; ·ñÔò·µ»Ø &false;¡£Ò»µ©Í·²¿ÐÅÏ¢ÒѾ±»·¢ËÍ£¬Ä㽫²»ÄÜÔÙʹÓà <function>header</function> º¯ÊýÀ´·¢ËÍÆäËüµÄÍ·²¿ÐÅÏ¢¡£Ê¹Óô˺¯Êý¿ÉÒÔʹÄã×î´óÏ޶ȵıÜÃâÀàËÆ "Duplicate headers ..." µÄ´íÎóÐÅÏ¢¡£ </para> <para> Èç¹û¿ÉÏȲÎÊý <parameter>file</parameter> ¼° <parameter>line</parameter> ±»Ö¸¶¨£¬Ôòº¯Êý»á·µ»ØÖ¸¶¨ÎļþÖ¸¶¨ÐÐÊýÆðÍ·²¿ÐÅÏ¢µÄ·¢ËÍÇé¿ö¡£ </para> <note> <simpara> <parameter>file</parameter> and <parameter>line</parameter> ²ÎÊýÔÚ PHP 4.3.0 °æ±¾Öб»¼ÓÈë¡£ </simpara> </note> <para> ¸ü¶àϸ½ÚµÄÌÖÂ۲μû <function>header</function>¡£ </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/phpdoc-zh/reference/http/functions/setcookie.xml?r=1.1&p=1 Index: phpdoc-zh/reference/http/functions/setcookie.xml +++ phpdoc-zh/reference/http/functions/setcookie.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <!-- $Author: yincheng $ --> <!-- EN-Revision: 1.12 Maintainer: Avenger Status: ready --> <!-- splitted from ./en/functions/http.xml, last change in rev 1.2 --> <refentry id="function.setcookie"> <refnamediv> <refname>setcookie</refname> <refpurpose>·¢ËÍÒ»¸ö cookie ÐÅÏ¢</refpurpose> </refnamediv> <refsect1> <title>ÃèÊö</title> <methodsynopsis> <type>boolean</type><methodname>setcookie</methodname> <methodparam><type>string</type><parameter>name</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>value</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>expire</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>path</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>domain</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>secure</parameter></methodparam> </methodsynopsis> <para> <function>setcookie</function> º¯ÊýÓÃÀ´½¨Á¢Ò»¸öÐ嵀 cookie µÄÐÅÏ¢¡£ºÍÆäËüÍ·²¿ÐÅÏ¢Ò»Ñù£¬cookies ±ØÐëÒªÊä³öÔÚÎļþµÄ<emphasis>×îÇ°Ãæ</emphasis>£¬Ò²¾ÍÒâζ×ÅÔÚÆä֮ǰ£¬Äã²»ÄÜÊä³öÈκÎ×Ö·û (ÕâÊǹ涨)¡£°üÀ¨ <literal><html></literal> ºÍ <literal><head></literal> ±êÇ©ÒÔ¼°Ò»Ð©¿Õ¸ñ¡£Èç¹ûÕâЩ±êÇ©ÔÚʹÓà <function>setcookie</function> º¯ÊýǰÊä³ö£¬º¯ÊýÔËÐÐÔò»áʧ°Ü²¢·µ»Ø &false;¡£ Ö»Òª <function>setcookie</function> º¯Êý³É¹¦ÔËÐУ¬²»¹Ü¸ÃÐÅÏ¢ÊÇ·ñ±»Óû§½ÓÊÜ£¬¶¼»á·µ»Ø &true;¡£ </para> <para> ³ýÁË <parameter>name</parameter> ÒÔÍ⣬ÆäËüËùÓвÎÊý¶¼ÊÇ¿ÉÑ¡µÄ¡£Èç¹ûÖ»ÓÐ name ²ÎÊý£¬Õ⽫»áɾ³ý¿Í»§¶ËÃû³ÆÎª name µÄ cookie¡£µ±È»£¬ÎªÁËÌø¹ýijЩ²ÎÊýµÄÉ趨£¬Äã¿ÉÒÔΪһЩ²ÎÊý¸³¿Õ×Ö·û (<emphasis>""</emphasis>)¡£µ«²ÎÊý <parameter>expire</parameter> ¼° <parameter>secure</parameter> µÄÀàÐÍÓ¦¸ÃΪÕûÊý (integers) ²¢ÇÒ²»Äܱ»¸³Îª¿Õ×Ö·û¡£Äã¿ÉÒÔÓà 0 À´´úÌæ(<emphasis>0</emphasis>)¡£²ÎÊý <parameter>expire</parameter> ÊÇÒ»¸ö Unix µÄʱ¼ä´Á£¬¿ÉÒÔÓà <function>time</function> »ò <function>mktime</function> º¯ÊýÀ´»ñµÃ¡£<parameter>secure</parameter> ²ÎÊý±íÃ÷¸Ã cookie Ö»ÔÚ°²È« HTTP Á¬½Óϲű»·¢ËÍ¡£ </para> <para> µ± cookies ±»ÉèÖú󣬱ã¿ÉÒÔÔÚÆäËüÒ³ÃæÍ¨¹ý <link linkend="reserved.variables.cookies">$_COOKIE</link> »ò <varname>$HTTP_COOKIE_VARS</varname> Êý×éÈ¡µÃÆäÖµ¡£ÐèҪעÒâµÄÊÇ£¬<link linkend="language.variables.superglobals">autoglobals</link> µÄ <varname>$_COOKIE</varname> ÐÎʽÊÊÓÃÓÚ PHP <ulink url="&url.php.release4.1.0;">4.1.0</ulink> »ò¸ü¸ß°æ±¾¡£¶ø <varname>$HTTP_COOKIE_VARS</varname> Ôò´Ó PHP 3 Æð¾Í¿ÉÒÔʹÓÃ. </para> <para> ÐèҪעÒâµÄ¼¸µã: <itemizedlist> <listitem> <simpara> Cookies ²»»áÔÚÄãÉèÖÃËüµÄ±¾Ò³ÉúЧ¡¢Òª²âÊÔÒ»¸ö cookie ÊÇ·ñ±»³É¹¦µÄÉ趨£¬Äã¿ÉÒÔÔÚÆäµ½ÆÚ֮ǰͨ¹ýÁíÍâÒ»¸öÒ³ÃæÀ´·ÃÎÊÆäÖµ¡£¹ýÆÚʱ¼äÊÇͨ¹ý²ÎÊý <parameter>expire</parameter> À´ÉèÖõġ£ </simpara> </listitem> <listitem> <simpara> Cookies ½«»á±»ÓëÆäͬÃûµÄºóÉ趨µÄ cookie Ëù¸²¸Ç¡£ </simpara> </listitem> <listitem> <simpara> ÔÚʵ¼ÊÔËÓÃÖУ¬Äã¿ÉÒÔ°Ñ Cookies µÄÃû³ÆÉèÖóÉÒ»¸öÊý×飬µ«ÊÇÊý×é cookie ÖеÄÿ¸öÔªËØµÄÖµ½«»á±»µ¥¶À±£´æÔÚÓû§µÄϵͳÖС£Äã¿ÉÒÔÊÔ×ÅÓÃ<function>explode</function> »ò <function>serialize</function> º¯ÊýÀ´°Ñ¶à¸ö cookie ֵдÈëµ½Ò»¸ö cookie ÎļþÖС£ </simpara> </listitem> </itemizedlist> </para> <simpara> ÔÚ PHP 3 ÖУ¬ÔÚͬһ¸ö PHP ½Å±¾Öжà´ÎʹÓà <function>setcookie</function> À´ÉèÖà cookie£¬½«»á°´ÕÕµ¹ÐòµÄ·½Ê½À´·Ö±ðÖ´ÐУ¬Èç¹ûÄãÏëÒªÔÚ²åÈëÁíÍâÒ»¸ö cookie ǰɾ³ýÒ»¸ö cookie,Äã±ØÐëÏȲåÈëÈ»ºóÔÙɾ³ý¡£ÔÚ PHP 4 À¶à´Îµ÷Óà <function>setcookie</function> ÔòÊǰ´ÕÕ˳ÐòÀ´Ö´Ðеġ£ </simpara> <para> ÏÂÃæÒ»Ð©Àý×Ó˵Ã÷ÁËÈçºÎ·¢ËÍ cookies: <example> <title><function>setcookie</function> sent examples</title> <programlisting role="php"> <![CDATA[ setcookie ("TestCookie", $value); setcookie ("TestCookie", $value,time()+3600); /* expire in 1 hour */ setcookie ("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1); ]]> </programlisting> </example> </para> <para> Ò»¸ö¹ýÆÚµÄ cookie ½«»á±»×Ô¶¯É¾³ý¡£Àý×Ó˵Ã÷ÁËÈçºÎɾ³ýÒ»¸ö cookies: <example> <title><function>setcookie</function> delete examples</title> <programlisting role="php"> <![CDATA[ // set the expiration date to one hour ago setcookie ("TestCookie", "", time() - 3600); setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1); ]]> </programlisting> </example> </para> <para> ҪעÒâµÄÊÇ cookie µÄÖµÔÚ·¢Ë͵Äʱºò»á±»×Ô¶¯µÄ±àÂë²¢±£´æ£¬¶øµ±Äã¶ÁÈ¡ËüµÄʱºò£¬ËüÓֻᱻ×Ô¶¯µÄ½âÂë²¢×Ô¶¯°Ñ×Ô¼º¸³Öµ¸øÓë×Ô¼ºÍ¬ÃûµÄÒ»¸ö±äÁ¿¡£Äã¿ÉÒÔͨ¹ýÏÂÃæ¼òµ¥µÄÀý×ÓÀ´¿´µ½: <informalexample> <programlisting role="php"> <![CDATA[ echo $TestCookie; echo $_COOKIE["TestCookie"]; ]]> </programlisting> </informalexample> </para> <para> ÄãÒ²¿ÉÒÔÉèÖÃÒ»¸öÊý×éÀ´´æ·Å cookie£¬°ÑÐí¶àÃû³Æ²»Í¬µÄ cookie ·Åµ½Ò»¸öÊý×éÖдæ·Å¡£ÕâÑùÄãÔÚ½ÓÊÕ cookie µÄʱºòÖ»ÐèÒªÒª»ñȡһ¸öÊý×é: <informalexample> <programlisting role="php"> <![CDATA[ setcookie ("cookie[three]", "cookiethree"); setcookie ("cookie[two]", "cookietwo"); setcookie ("cookie[one]", "cookieone"); if (isset ($cookie)) { while (list ($name, $value) = each ($cookie)) { echo "$name == $value<br>\n"; } } ]]> </programlisting> </informalexample> </para> <para> ¹ØÓÚ cookies ¸ü¶àµÄ½éÉÜ£¬¿ÉÒԲο¼Íø¾°¹«Ë¾µÄ cookies ˵Ã÷Êé <ulink url="&spec.cookies;">&spec.cookies;</ulink>. </para> <simpara> Netscape Communicator 4.05 ¼° Microsoft Internet Explorer 3.x ÔÚ cookie µÄ·¾¶ºÍʱ¼äûÓÐÉèÖõÄÇé¿öÏ»á³öÏÖһЩÎÊÌâ¡£ </simpara> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->