From 2d657e313658cf087a57dd5673cacca0d3fc6aa6 Mon Sep 17 00:00:00 2001 From: Philip Olson Date: Tue, 21 Jan 2003 21:26:43 +0000 Subject: [PATCH] Moved and greatly expanded parameter information into a table. And mention register_globals and $_REQUEST as well as print_r($_COOKIE) for debugging. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@112981 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/http/functions/setcookie.xml | 126 ++++++++++++++++++++++--- 1 file changed, 113 insertions(+), 13 deletions(-) diff --git a/reference/http/functions/setcookie.xml b/reference/http/functions/setcookie.xml index 559686e653..aa655e6e23 100644 --- a/reference/http/functions/setcookie.xml +++ b/reference/http/functions/setcookie.xml @@ -1,5 +1,6 @@ + - + @@ -33,17 +34,105 @@ 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 + also replace an 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. + argument. Because the expire and + secure arguments are integers, they cannot + be skipped with an empty string, use a zero (0) + instead. The following table explains each parameter of + setcookie: + + + + <function>setcookie</function> parameters explained + + + + Parameter + Description + Examples + + + + + name + + The name of the cookie. + + + 'cookiename' is called as $_COOKIE['cookiename'] + + + + value + + The value of the cookie. This value is stored on the clients + computer; do not store sensitive information. + + + Assuming the name is 'cookiename', this + value is retrieved through $_COOKIE['cookiename'] + + + + expire + + The time the cookie expires. This is a unix timestamp so is + in number of seconds since the epoch. In otherwords, you'll + most likely set this with the time function + plus the number of seconds before you want it to expire. Or + you might use mktime. + + + time()+60*60*24*30 will set the cookie to + expire in 30 days. If not set, the cookie will expire at + the end of the session (when the browser closes). + + + + path + + The path on the server in which the cookie will be available on. + + + If set to '/', the cookie will be available + within the entire domain. If set to + '/foo/', the cookie will only be available + within the /foo/ directory and all + sub-directories such as /foo/bar/ of + domain. The default value is the + current directory that the cookie is being set in. + + + + domain + + The domain that the cookie is available. + + + To make the cookie available on all subdomains of example.com + then you'd set it to '.example.com'. The + . is not required but makes it compatable + with more browsers. Setting it to www.example.com + will make the cookie only available in the www + subdomain. + + + + secure + + Indicates that the cookie should only be transmitted over a + secure HTTPS connection. When set to 1, the + cookie will only be set if a secure connection exists. The default + is 0. + + + 0 or 1 + + + + +
Once the cookies have been set, they can be accessed on the next page load @@ -52,8 +141,18 @@ autoglobals such as $_COOKIE became available in PHP 4.1.0. - $HTTP_COOKIE_VARS has existed since PHP 3. + $HTTP_COOKIE_VARS has existed since PHP 3. Cookie + values also exist in + $_REQUEST. + + + If the PHP directive register_globals + is set to on then cookie values will also be made into + variables. In our examples below, $TextCookie will + exist. It's recommended to use $_COOKIE. + + Common Pitfalls: @@ -63,7 +162,8 @@ 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. + parameter. A nice way to debug the existence of cookies is by + simply calling print_r($_COOKIE);.