php-doc-en/reference/http/functions/setcookie.xml

161 lines
6.1 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="gb2312"?>
<!-- $Revision: 1.9 $ -->
<!-- splitted from ./en/functions/http.xml, last change in rev 1.2 -->
<refentry id="function.setcookie">
<refnamediv>
<refname>setcookie</refname>
<refpurpose><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> cookie <20><>Ϣ</refpurpose>
</refnamediv>
<refsect1>
<title><EFBFBD><EFBFBD><EFBFBD><EFBFBD></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> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>µ<EFBFBD> cookie <20><><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>Ϣһ<CFA2><D2BB><EFBFBD><EFBFBD>cookies
<20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><emphasis><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD></emphasis><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ζ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><EFBFBD>ַ<EFBFBD>
(<28><><EFBFBD>ǹ涨)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<literal>&lt;html></literal> <20><> <literal>&lt;head></literal>
<20><>ǩ<EFBFBD>Լ<EFBFBD>һЩ<D2BB>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9>ǩ<EFBFBD><C7A9>ʹ<EFBFBD><CAB9> <function>setcookie</function> <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD> &false;<EFBFBD><EFBFBD>
ֻҪ <function>setcookie</function> <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD>ܸ<EFBFBD><DCB8><EFBFBD>Ϣ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><E1B7B5> &true;<EFBFBD><EFBFBD>
</para>
<para>
<20><><EFBFBD><EFBFBD> <parameter>name</parameter> <20><><EFBFBD><EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ѡ<EFBFBD>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB> name
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E2BDAB>ɾ<EFBFBD><C9BE><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ name
<20><> cookie<69><65><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ijЩ<C4B3><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪһЩ<D2BB><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
(<emphasis>&quot;&quot;</emphasis>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<parameter>expire</parameter> <20><>
<parameter>secure</parameter> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD> (integers) <20><><EFBFBD>Ҳ<EFBFBD><D2B2>ܱ<EFBFBD><DCB1><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<emphasis>0</emphasis>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<parameter>expire</parameter> <20><>һ<EFBFBD><D2BB> Unix <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<function>time</function> <20><> <function>mktime</function>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD><parameter>secure</parameter> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cookie
ֻ<>ڰ<EFBFBD>ȫ HTTP <20><><EFBFBD><EFBFBD><EFBFBD>²ű<C2B2><C5B1><EFBFBD><EFBFBD>͡<EFBFBD>
</para>
<para>
<20><> cookies <20><><EFBFBD><EFBFBD><EFBFBD>ú󣬱<C3BA><F3A3ACB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>ͨ<EFBFBD><CDA8> <link linkend="reserved.variables.cookies">$_COOKIE</link>
<20><> <varname>$HTTP_COOKIE_VARS</varname> <20><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ҫע<D2AA><D7A2><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD><link linkend="language.variables.superglobals">autoglobals</link>
<20><> <varname>$_COOKIE</varname> <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PHP
<ulink url="&url.php.release4.1.0;">4.1.0</ulink> <20><><EFBFBD><EFBFBD><EFBFBD>߰汾<DFB0><E6B1BE><EFBFBD><EFBFBD>
<varname>$HTTP_COOKIE_VARS</varname> <20><><EFBFBD><EFBFBD> PHP 3 <20><><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD>ʹ<EFBFBD><CAB9>.
</para>
<para>
<20><>Ҫע<D2AA><D7A2><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>:
<itemizedlist>
<listitem>
<simpara>
Cookies <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>ҳ<EFBFBD><D2B3>Ч<EFBFBD><D0A7>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> cookie <20>Ƿ񱻳ɹ<F1B1BBB3><C9B9><EFBFBD><EFBFBD><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4B5BD>֮ǰͨ<C7B0><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<parameter>expire</parameter> <20><><EFBFBD><EFBFBD><EFBFBD>õġ<C3B5>
</simpara>
</listitem>
<listitem>
<simpara>
Cookies <20><><EFBFBD><EFBFBD><E1B1BB><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><E8B6A8> cookie <20><><EFBFBD><EFBFBD><EFBFBD>ǡ<EFBFBD>
</simpara>
</listitem>
<listitem>
<simpara>
<20><>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>԰<EFBFBD> Cookies <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cookie <20>е<EFBFBD>ÿ<EFBFBD><C3BF>Ԫ<EFBFBD>ص<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><E1B1BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ϵͳ<CFB5>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><function>explode</function>
<20><> <function>serialize</function> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѷ<EFBFBD><D1B6><EFBFBD> cookie ֵд<D6B5>һ<EBB5BD><D2BB> cookie <20>ļ<EFBFBD><C4BC>С<EFBFBD>
</simpara>
</listitem>
</itemizedlist>
</para>
<simpara>
<20><> PHP 3 <20>У<EFBFBD><D0A3><EFBFBD>ͬһ<CDAC><D2BB> PHP <20>ű<EFBFBD><C5B1>ж<EFBFBD><D0B6><EFBFBD>ʹ<EFBFBD><CAB9> <function>setcookie</function>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cookie<69><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ķ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ֱ<EFBFBD>ִ<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> cookie
ǰɾ<C7B0><C9BE>һ<EFBFBD><D2BB> cookie,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PHP 4 <20><EFBFBD><EFA3AC><EFBFBD>ε<EFBFBD><CEB5><EFBFBD>
<function>setcookie</function> <20><><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>ִ<EFBFBD>еġ<D0B5>
</simpara>
<para>
<20><><EFBFBD><EFBFBD>һЩ<D2BB><D0A9><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>η<EFBFBD><CEB7><EFBFBD> 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>
һ<><D2BB><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD> cookie <20><><EFBFBD><EFBFBD>Զ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>һ<EFBFBD><D2BB> 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>
Ҫע<D2AA><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cookie <20><>ֵ<EFBFBD>ڷ<EFBFBD><DAB7>͵<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ı<EFBFBD><C4B1><EFBFBD><EBB2A2><EFBFBD><EFBFBD><E6A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻᱻ<D6BB>Զ<EFBFBD><D4B6>Ľ<EFBFBD><C4BD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򵥵<EFBFBD><F2B5A5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
<informalexample>
<programlisting role="php">
<![CDATA[
echo $TestCookie;
echo $_COOKIE["TestCookie"];
]]>
</programlisting>
</informalexample>
</para>
<para>
<20><>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cookie<69><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>ͬ<EFBFBD><CDAC> cookie <20>ŵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>š<EFBFBD><C5A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD> cookie
<20><>ʱ<EFBFBD><CAB1>ֻ<EFBFBD><D6BB>ҪҪ<D2AA><D2AA>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
<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>
<20><><EFBFBD><EFBFBD> cookies <20><><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>Բο<D4B2><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾<EFBFBD><CBBE> cookies ˵<><CBB5><EFBFBD><EFBFBD>
<ulink url="&spec.cookies;">&spec.cookies;</ulink>.
</para>
<simpara>
Netscape Communicator 4.05 <20><> Microsoft Internet Explorer 3.x <20><> cookie <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>»<EFBFBD><C2BB><EFBFBD><EFBFBD><EFBFBD>һЩ<D2BB><D0A9><EFBFBD>
</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
-->