manual/en/features.cookies.php

20130822_rev01 · COMPARED WITH 20130702_rev01 · ARCHIVE SNAPSHOT, DATE APPROXIMATE

Full text changes — 20130702_rev01 to 20130822_rev01

1Change language:
2
3PHP transparently supports HTTP cookies. Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users. You can set cookies using the [setcookie()](http://www.php.net/manual/en/function.setcookie.php) or [setrawcookie()](http://www.php.net/manual/en/function.setrawcookie.php) function. Cookies are part of the HTTP header, so [setcookie()](http://www.php.net/manual/en/function.setcookie.php) must be called before any output is sent to the browser. This is the same limitation that [header()](http://www.php.net/manual/en/function.header.php) has. You can use the [output buffering functions](http://www.php.net/manual/en/ref.outcontrol.php) to delay the script output until you have decided whether or not to set any cookies or send any headers.
4
5Any cookies sent to you from the client will automatically be included into a [$\_COOKIE](http://www.php.net/manual/en/reserved.variables.cookies.php) auto-global array if [variables\_order](http://www.php.net/manual/en/ini.core.php) contains "C". If you wish to assign multiple values to a single cookie, just add _\[\]_ to the cookie name.
6
7Depending on [register\_globals](http://www.php.net/manual/en/ini.core.php), regular PHP variables can be created from cookies. However it's not recommended to rely on them as this feature is often turned off for the sake of security. $HTTP\_COOKIE\_VARS is also set in earlier versions of PHP when the [track\_vars](http://www.php.net/manual/en/ini.core.php) configuration variable is set. (This setting is always on since PHP 4.0.3.)
8
9For more details, including notes on browser bugs, see the [setcookie()](http://www.php.net/manual/en/function.setcookie.php) and [setrawcookie()](http://www.php.net/manual/en/function.setrawcookie.php) function.
10
1116
212
313[**_ingen at stocken.ws_**](http://www.php.net/manual/en/features.cookies.php) [¶](http://www.php.net/manual/en/features.cookies.php)
414
515**6 years ago**
616
2737`* You could use session_set_save_handler and make sure the session ID is generated in the open function. I haven't done that so I can't make any comments on it yet.`
2838
29391
3040
3141[**_Anonymous_**](http://www.php.net/manual/en/features.cookies.php) [¶](http://www.php.net/manual/en/features.cookies.php)
3242
33**2 months ago**
43**4 months ago**
3444
3545`Your note is too short. Trying to test the notes system? Save us the trouble of deleting your test, and don't. It works.`
3646
37471
3848
3949[**_mega-squall at caramail dot com_**](http://www.php.net/manual/en/features.cookies.php) [¶](http://www.php.net/manual/en/features.cookies.php)
4757`IMPORTANT NOTE : This disables the ability of using the back button if you send the session ID via POST or GET.`
4858
49590
5060
5161[**_meetyashah at gmail dot com_**](http://www.php.net/manual/en/features.cookies.php) [¶](http://www.php.net/manual/en/features.cookies.php)
5262
53**2 months ago**
63**3 months ago**
5464
5565`PAGE 1`
5666
5767`<?php echo $_COOKIE["first"]; ?> PAGE 2`
5868
5969`<?php if(isset($_COOKIE["first"])) { echo $_COOKIE["first"];} echo '<br />'; if(isset($_COOKIE["second"])){ echo $_COOKIE["second"]; } echo '<br />'; if(isset($_COOKIE["third"])){ echo $_COOKIE["third"]; } ?>`