From a98ff04e04c1b6e596460dd2032c91447545f5a7 Mon Sep 17 00:00:00 2001 From: bole Chen Date: Thu, 7 Nov 2002 04:25:07 +0000 Subject: [PATCH] finished git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@102839 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/http/functions/setcookie.xml | 123 +++++++++---------------- 1 file changed, 45 insertions(+), 78 deletions(-) diff --git a/reference/http/functions/setcookie.xml b/reference/http/functions/setcookie.xml index 434653e419..a395b3dc37 100644 --- a/reference/http/functions/setcookie.xml +++ b/reference/http/functions/setcookie.xml @@ -1,13 +1,13 @@ - + setcookie - Send a cookie + 发送一个 cookie 信息 - Description + 描述 booleansetcookie stringname @@ -18,81 +18,65 @@ intsecure - setcookie defines a cookie to be sent along - with the rest of the HTTP headers. Like other headers, cookies - must be sent before any output from your - script (this is a protocol restriction). This requires that you - place calls to this function prior to any output, including - <html> and <head> tags - as well as any whitespace. If output exists prior to calling this - function, setcookie will fail and return &false;. - If setcookie successfully runs, it will return - &true;. This does not indicate whether the user accepted the cookie. + setcookie 函数用来建立一个新的 cookie 的信息。和其它头部信息一样,cookies + 必须要输出在文件的最前面,也就意味着在其之前,你不能输出任何字符 + (这是规定)。包括 + <html><head> + 标签以及一些空格。如果这些标签在使用 setcookie 函数前输出,函数运行则会失败并返回 &false;。 + 只要 setcookie 函数成功运行,不管该信息是否被用户接受,都会返回 &true;。 - All the arguments except the name 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 - ("") in order to skip that - argument. The expire and - secure arguments are integers and cannot - be skipped with an empty string. Use a zero - (0) instead. The - expire argument is a regular Unix time - integer as returned by the time or - mktime functions. The - secure indicates that the cookie should - only be transmitted over a secure HTTPS connection. + 除了 name 以外,其它所有参数都是可选的。如果只有 name + 参数,这将会删除客户端名称为 name + 的 cookie。当然,为了跳过某些参数的设定,你可以为一些参数赋空字符 + ("")。但参数 + expire 及 + secure 的类型应该为整数 (integers) 并且不能被赋为空字符。你可以用 0 + 来代替(0)。参数 + expire 是一个 Unix 的时间戳,可以用 + timemktime + 函数来获得。secure 参数表明该 cookie + 只在安全 HTTP 连接下才被发送。 - Once the cookies have been set, they can be accessed on the next page load - with the $_COOKIE or - $HTTP_COOKIE_VARS arrays. Note, - autoglobals - such as $_COOKIE became available in PHP - 4.1.0. - $HTTP_COOKIE_VARS has existed since PHP 3. + 当 cookies 被设置后,便可以在其它页面通过 $_COOKIE + 或 $HTTP_COOKIE_VARS 数组取得其值。需要注意的是,autoglobals + 的 $_COOKIE 形式适用于 PHP + 4.1.0 或更高版本。而 + $HTTP_COOKIE_VARS 则从 PHP 3 起就可以使用. - Common Pitfalls: + 需要注意的几点: - 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 expire - parameter. + Cookies 不会在你设置它的本页生效、要测试一个 cookie 是否被成功的设定,你可以在其到期之前通过另外一个页面来访问其值。过期时间是通过参数 + expire 来设置的。 - Cookies must be deleted with the same parameters as they were set with. + Cookies 将会被与其同名的后设定的 cookie 所覆盖。 - 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 explode or - serialize to set one cookie with multiple names - and values. + 在实际运用中,你可以把 Cookies 的名称设置成一个数组,但是数组 cookie 中的每个元素的值将会被单独保存在用户的系统中。你可以试着用explode + 或 serialize 函数来把多个 cookie 值写入到一个 cookie 文件中。 - In PHP 3, multiple calls to setcookie 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 - setcookie are performed in the order called. + 在 PHP 3 中,在同一个 PHP 脚本中多次使用 setcookie + 来设置 cookie,将会按照倒序的方式来分别执行,如果你想要在插入另外一个 cookie + 前删除一个 cookie,你必须先插入然后再删除。在 PHP 4 里,多次调用 + setcookie 则是按照顺序来执行的。 - Some examples follow how to send cookies: + 下面一些例子说明了如何发送 cookies: - <function>setcookie</function> send examples + <function>setcookie</function> sent examples - 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: <function>setcookie</function> delete examples @@ -118,11 +100,7 @@ setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1); - 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 的值在发送的时候会被自动的编码并保存,而当你读取它的时候,它又会被自动的解码并自动把自己赋值给与自己同名的一个变量。你可以通过下面简单的例子来看到: - 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 + 的时候只需要要获取一个数组: - For more information on cookies, see Netscape's cookie - specification at &spec.cookies;. + 关于 cookies 更多的介绍,可以参考网景公司的 cookies 说明书 + &spec.cookies;. - Microsoft Internet Explorer 4 with Service Pack 1 applied does - not correctly deal with cookies that have their path parameter - set. - - - 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 的路径和时间没有设置的情况下会出现一些问题。 @@ -190,4 +157,4 @@ End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 ---> +--> \ No newline at end of file