git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@102781 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
bole Chen 2002-11-06 16:21:40 +00:00
parent 08a441b675
commit 06e43a49e3
4 changed files with 84 additions and 134 deletions

View file

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.6 $ -->
<!-- $Revision: 1.7 $ -->
<!-- splitted from ./en/functions/http.xml, last change in rev 1.2 -->
<refentry id="function.header">
<refnamediv>
<refname>header</refname>
<refpurpose>Send a raw HTTP header</refpurpose>
<refpurpose>向浏览器发送一个 HTTP 头部信息</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<title>描述</title>
<methodsynopsis>
<type>int</type><methodname>header</methodname>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
@ -15,17 +15,14 @@
<methodparam choice="opt"><type>int</type><parameter>http_reponse_code</parameter></methodparam>
</methodsynopsis>
<para>
<function>header</function> is used to send raw
<acronym>HTTP</acronym> headers. See the <ulink
url="&spec.http1.1;">HTTP/1.1 specification</ulink> for more
information on <acronym>HTTP</acronym> headers.
<function>header</function> 函数用来发送一个 <acronym>HTTP</acronym>
头部信息到客户端的浏览器。有关 <acronym>HTTP</acronym> 头部信息的更多内容参见官方文档
<ulink url="&spec.http1.1;">HTTP/1.1 specification</ulink>
</para>
<para>
The optional <parameter>replace</parameter> parameter indicates
whether the header should replace a previous similar header, or
add a second header of the same type. By default it will replace,
but if you pass in &false; as the second argument you can force
multiple headers of the same type. For example:
可选参数 <parameter>replace</parameter>
用来表示当出现两个相似的头部信息时,是替换前一个相同的头部信息还是增加一个相同的头部信息。默认为替换,如果你将其设为
&false; 则可以多次发送相同的头部信息。例如:
<informalexample>
<programlisting role="php">
<![CDATA[
@ -38,15 +35,12 @@ header('WWW-Authenticate: NTLM', FALSE);
</informalexample>
</para>
<para>
The second optional <parameter>http_response_code</parameter> force the
HTTP response code to the specified value. (This parameter is available
in PHP 4.3.0 and higher.)
第二个可选参数 <parameter>http_response_code</parameter> 表示 HTTP
的头部信息的代码。(此参数在PHP 4.3.0 被加入。)
</para>
<para>
There are two special-case header calls. The first is a header
that starts with the string "<literal>HTTP/</literal>" (case is not
significant), which will be used to figure out the HTTP status
code to send. For example, if you have configured Apache to
头部信息的格式有两种形式。一种情况是以字符 “<literal>HTTP/</literal>” (不区分大小写)开头的which will be used to figure out the HTTP status
code to send。例如,如果你if you have configured Apache to
use a PHP script to handle requests for missing files (using
the <literal>ErrorDocument</literal> directive), you may want to
make sure that your script generates the proper status code.
@ -61,6 +55,7 @@ header('WWW-Authenticate: NTLM', FALSE);
</informalexample>
<note>
<para>
HTTP 头部信息经常首先被发送到客户端,
The HTTP status header line will always be the first sent
to the client, regardless of the actual <function>header</function>
call beeing the first or not. The status may be overridden
@ -70,9 +65,8 @@ header('WWW-Authenticate: NTLM', FALSE);
</note>
<note>
<para>
In PHP 3, this only works when PHP is compiled as an Apache
module. You can achieve the same effect using the
<literal>Status</literal> header.
在 PHP 3 中,此函数只在 PHP 以 Apache 的模块化运行的时候有效。你可以使用 <literal>Status</literal>
来达到相同的效果。
<informalexample>
<programlisting role="php">
<![CDATA[
@ -86,7 +80,7 @@ header("Status: 404 Not Found");
</note>
</para>
<para>
The second special case is the "Location:" header. Not only does
第二种特殊情况是以 "Location:" 开头的信息。Not only does
it send this header back to the browser, but it also returns a
<literal>REDIRECT</literal> (302) status code to the browser unless
some <literal>3xx</literal> status code has already been set.
@ -104,13 +98,11 @@ exit; /* Make sure that code below does
</para>
<note>
<para>
HTTP/1.1 requires an absolute <acronym>URI</acronym> as argument to
HTTP/1.1 标准需要一个绝对地址的 <acronym>URI</acronym> 做为
<ulink url="&spec.http1.1;-sec14.html#sec14.30">Location:</ulink>
including the scheme, hostname and absolute path, but
some clients accept relative URIs. You can usually use
<literal>$_SERVER['HTTP_HOST']</literal>, <literal>$_SERVER['PHP_SELF']</literal>
and <function>dirname</function> to make an absolute URI from a
relative one yourself:
的参数, 但有一些客户端支持虚拟的路径。你通常可以使用
<literal>$_SERVER['HTTP_HOST']</literal><literal>$_SERVER['PHP_SELF']</literal>
<function>dirname</function> 函数来自己获取所需要的绝对路径:
<informalexample>
<programlisting>
<![CDATA[
@ -125,11 +117,8 @@ header("Location: http://".$_SERVER['HTTP_HOST']
</para>
</note>
<para>
PHP scripts often generate dynamic content that must not be cached
by the client browser or any proxy caches between the server and the
client browser. Many proxies and clients can be forced to disable
caching with
<informalexample>
PHP 脚本通常是动态改变的。可有些客户端或一些代理服务器会把一些浏览过的内容给缓冲起来,这样您更新的脚本就不能被客户端及时的发现,你可以通过发送一些类似下面例子中的头部信息来禁止他们缓存你的网页。
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
@ -145,16 +134,15 @@ header("Pragma: no-cache"); // HTTP/1.0
</informalexample>
<note>
<para>
You may find that your pages aren't cached even if you don't
output all of the headers above. There are a number of options
你可能会发现即使你没有把上边的代码全部输出你的网页也没有被缓冲起来。这是因为一些用户在他们的浏览器的设置There are a number of options
that users may be able to set for their browser that change its
default caching behavior. By sending the headers above, you should
override any settings that may otherwise cause the output of your
script to be cached.
</para>
<para>
Additionally, <function>session_cache_limiter</function> and
the <literal>session.cache_limiter</literal> configuration
另外,<function>session_cache_limiter</function>
<literal>session.cache_limiter</literal> configuration
setting can be used to automatically generate the correct
caching-related headers when sessions are being used.
</para>

View file

@ -1,39 +1,35 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./en/functions/http.xml, last change in rev 1.7 -->
<refentry id="function.headers-sent">
<refnamediv>
<refname>headers_sent</refname>
<refpurpose>Returns &true; if headers have been sent</refpurpose>
<refpurpose>测试头部信息是否已经被发送,如果是,返回 &true;</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<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>
</methodsynopsis>
<para>
This function returns &true; if the HTTP headers have already been
sent, &false; otherwise. You can't add any more header lines using
the <function>header</function> function once the header block has
already been sent. Using this function you can at least prevent
getting the "Duplicate headers ..." error messages.
这个函数测试脚本中头部信息是否已经发送,如果是则返回 &true; 否则返回 &false;。一旦头部信息已经被发送,你将不能再使用 <function>header</function>
函数来发送其它的头部信息。使用此函数可以使你最大限度的避免类似 "Duplicate headers ..." 的错误信息。
</para>
<para>
The function will return the php source file and line number where
output started in the optional <parameter>file</parameter> and
<parameter>line</parameter> parameters if these are given.
如果可先参数 <parameter>file</parameter>
<parameter>line</parameter>
被指定,则函数会返回指定文件指定行数起头部信息的发送情况。
</para>
<note>
<simpara>
<parameter>file</parameter> and <parameter>line</parameter> where
added for PHP 4.3.0.
<parameter>file</parameter> and <parameter>line</parameter>
参数在 PHP 4.3.0 版本中被加入。
</simpara>
</note>
<para>
See also <function>header</function> for a more detailed discussion
of the matters involved.
更多细节的讨论参见 <function>header</function>
</para>
</refsect1>
</refentry>

View file

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- $Revision: 1.6 $ -->
<!-- splitted from ./en/functions/http.xml, last change in rev 1.2 -->
<refentry id="function.setcookie">
<refnamediv>
<refname>setcookie</refname>
<refpurpose>Send a cookie</refpurpose>
<refpurpose>发送一个 cookie 信息</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<title>描述</title>
<methodsynopsis>
<type>boolean</type><methodname>setcookie</methodname>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
@ -18,81 +18,65 @@
<methodparam choice="opt"><type>int</type><parameter>secure</parameter></methodparam>
</methodsynopsis>
<para>
<function>setcookie</function> defines a cookie to be sent along
with the rest of the HTTP headers. Like other headers, cookies
must be sent <emphasis>before</emphasis> any output from your
script (this is a protocol restriction). This requires that you
place calls to this function prior to any output, including
<literal>&lt;html></literal> and <literal>&lt;head></literal> tags
as well as any whitespace. If output exists prior to calling this
function, <function>setcookie</function> will fail and return &false;.
If <function>setcookie</function> successfully runs, it will return
&true;. This does not indicate whether the user accepted the cookie.
<function>setcookie</function> 函数用来建立一个新的 cookie 的信息。和其它头部信息一样cookies
必须要输出在文件的<emphasis>最前面</emphasis>,也就意味着在其之前,你不能输出任何字符
(这是规定)。包括
<literal>&lt;html></literal><literal>&lt;head></literal>
标签以及一些空格。如果这些标签在使用 <function>setcookie</function> 函数前输出,函数运行则会失败并返回 &false;
只要 <function>setcookie</function> 函数成功运行,不管该信息是否被用户接受,都会返回 &true;
</para>
<para>
All the arguments except the <parameter>name</parameter> argument
are optional. If only the name argument is present, the cookie
by that name will be deleted from the remote client. You may
also replace any argument with an empty string
(<emphasis>&quot;&quot;</emphasis>) in order to skip that
argument. The <parameter>expire</parameter> and
<parameter>secure</parameter> arguments are integers and cannot
be skipped with an empty string. Use a zero
(<emphasis>0</emphasis>) instead. The
<parameter>expire</parameter> argument is a regular Unix time
integer as returned by the <function>time</function> or
<function>mktime</function> functions. The
<parameter>secure</parameter> indicates that the cookie should
only be transmitted over a secure HTTPS connection.
除了 <parameter>name</parameter> 以外,其它所有参数都是可选的。如果只有 name
参数,这将会删除客户端名称为 name
的 cookie。当然为了跳过某些参数的设定你可以为一些参数赋空字符
(<emphasis>&quot;&quot;</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>
Once the cookies have been set, they can be accessed on the next page load
with the <link linkend="reserved.variables.cookies">$_COOKIE</link> or
<varname>$HTTP_COOKIE_VARS</varname> arrays. Note,
<link linkend="language.variables.superglobals">autoglobals</link>
such as <varname>$_COOKIE</varname> became available in PHP
<ulink url="&url.php.release4.1.0;">4.1.0</ulink>.
<varname>$HTTP_COOKIE_VARS</varname> has existed since PHP 3.
当 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>
Common Pitfalls:
需要注意的几点:
<itemizedlist>
<listitem>
<simpara>
Cookies will not become visible until the next loading of a page that
the cookie should be visible for. To test if a cookie was successfully
set, check for the cookie on a next loading page before the cookie
expires. Expire time is set via the <parameter>expire</parameter>
parameter.
Cookies 不会在你设置它的本页生效、要测试一个 cookie 是否被成功的设定,你可以在其到期之前通过另外一个页面来访问其值。过期时间是通过参数
<parameter>expire</parameter> 来设置的。
</simpara>
</listitem>
<listitem>
<simpara>
Cookies must be deleted with the same parameters as they were set with.
Cookies 将会被与其同名的后设定的 cookie 所覆盖。
</simpara>
</listitem>
<listitem>
<simpara>
Cookies names can be set as array names and will be available to your
PHP scripts as arrays but seperate cookies are stored on the users
system. Consider <function>explode</function> or
<function>serialize</function> to set one cookie with multiple names
and values.
在实际运用中,你可以把 Cookies 的名称设置成一个数组,但是数组 cookie 中的每个元素的值将会被单独保存在用户的系统中。你可以试着用<function>explode</function>
<function>serialize</function> 函数来把多个 cookie 值写入到一个 cookie 文件中。
</simpara>
</listitem>
</itemizedlist>
</para>
<simpara>
In PHP 3, multiple calls to <function>setcookie</function> in the same
script will be performed in reverse order. If you are trying to
delete one cookie before inserting another you should put the
insert before the delete. In PHP 4, multiple calls to
<function>setcookie</function> are performed in the order called.
在 PHP 3 中,在同一个 PHP 脚本中多次使用 <function>setcookie</function>
来设置 cookie将会按照倒序的方式来分别执行如果你想要在插入另外一个 cookie
前删除一个 cookie,你必须先插入然后再删除。在 PHP 4 里,多次调用
<function>setcookie</function> 则是按照顺序来执行的。
</simpara>
<para>
Some examples follow how to send cookies:
下面一些例子说明了如何发送 cookies:
<example>
<title><function>setcookie</function> send examples</title>
<title><function>setcookie</function> sent examples</title>
<programlisting role="php">
<![CDATA[
setcookie ("TestCookie", $value);
@ -103,9 +87,7 @@ setcookie ("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1);
</example>
</para>
<para>
When deleting a cookie you should assure that the expiration date
is in the past, to trigger the removal mechanism in your browser.
Examples follow how to delete cookies sent in previous example:
一个过期的 cookie 将会被自动删除。例子说明了如何删除一个 cookies:
<example>
<title><function>setcookie</function> delete examples</title>
<programlisting role="php">
@ -118,11 +100,7 @@ setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1);
</example>
</para>
<para>
Note that the value portion of the cookie will automatically be
urlencoded when you send the cookie, and when it is received, it
is automatically decoded and assigned to a variable by the same
name as the cookie name. To see the contents of our test
cookie in a script, simply use one of the following examples:
要注意的是 cookie 的值在发送的时候会被自动的编码并保存,而当你读取它的时候,它又会被自动的解码并自动把自己赋值给与自己同名的一个变量。你可以通过下面简单的例子来看到:
<informalexample>
<programlisting role="php">
<![CDATA[
@ -133,11 +111,8 @@ echo $_COOKIE["TestCookie"];
</informalexample>
</para>
<para>
You may also set array cookies by using array notation in the
cookie name. This has the effect of setting as many cookies as
you have array elements, but when the cookie is received by your
script, the values are all placed in an array with the cookie's
name:
你也可以设置一个数组来存放 cookie把许多名称不同的 cookie 放到一个数组中存放。这样你在接收 cookie
的时候只需要要获取一个数组:
<informalexample>
<programlisting role="php">
<![CDATA[
@ -154,19 +129,11 @@ if (isset ($cookie)) {
</informalexample>
</para>
<para>
For more information on cookies, see Netscape's cookie
specification at <ulink
url="&spec.cookies;">&spec.cookies;</ulink>.
关于 cookies 更多的介绍,可以参考网景公司的 cookies 说明书
<ulink url="&spec.cookies;">&spec.cookies;</ulink>.
</para>
<simpara>
Microsoft Internet Explorer 4 with Service Pack 1 applied does
not correctly deal with cookies that have their path parameter
set.
</simpara>
<simpara>
Netscape Communicator 4.05 and Microsoft Internet Explorer 3.x
appear to handle cookies incorrectly when the path and time
are not set.
Netscape Communicator 4.05 及 Microsoft Internet Explorer 3.x 在 cookie 的路径和时间没有设置的情况下会出现一些问题。
</simpara>
</refsect1>
</refentry>

View file

@ -1,15 +1,14 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- $Revision: 1.5 $ -->
<reference id="ref.http">
<title>HTTP functions</title>
<title>HTTP 相关函数</title>
<titleabbrev>HTTP</titleabbrev>
<partintro>
<section id="http.intro">
&reftitle.intro;
<para>
These functions let you manipulate the output sent back to the
remote browser right down to the HTTP protocol level.
这些函数可以让你依据 HTTP 标准协议向客户端浏览器发送头部信息。
</para>
</section>