<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Cookies</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.http-auth.html">HTTP authentication with PHP</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.sessions.html">Sessions</a></div> <div class="up"><a href="features.html">Features</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="features.cookies" class="chapter"> <h1>Cookies</h1> <p class="para"> PHP transparently supports <acronym title="Hypertext Transfer Protocol">HTTP</acronym> 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 <span class="function"><a href="function.setcookie.html" class="function">setcookie()</a></span> or <span class="function"><a href="function.setrawcookie.html" class="function">setrawcookie()</a></span> function. Cookies are part of the <acronym title="Hypertext Transfer Protocol">HTTP</acronym> header, so <span class="function"><a href="function.setcookie.html" class="function">setcookie()</a></span> must be called before any output is sent to the browser. This is the same limitation that <span class="function"><a href="function.header.html" class="function">header()</a></span> has. You can use the <a href="ref.outcontrol.html" class="link">output buffering functions</a> to delay the script output until you have decided whether or not to set any cookies or send any headers. </p> <p class="para"> Any cookies sent to you from the client will automatically be included into a <var class="varname"><var class="varname"><a href="reserved.variables.cookies.html" class="classname">$_COOKIE</a></var></var> auto-global array if <a href="ini.core.html#ini.variables-order" class="link">variables_order</a> contains "C". If you wish to assign multiple values to a single cookie, just add <em>[]</em> to the cookie name. </p> <p class="para"> Depending on <a href="ini.core.html#ini.register-globals" class="link">register_globals</a>, 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. <var class="varname"><var class="varname">$HTTP_COOKIE_VARS</var></var> is also set in earlier versions of PHP when the <a href="ini.core.html#ini.track-vars" class="link">track_vars</a> configuration variable is set. (This setting is always on since PHP 4.0.3.) </p> <p class="para"> For more details, including notes on browser bugs, see the <span class="function"><a href="function.setcookie.html" class="function">setcookie()</a></span> and <span class="function"><a href="function.setrawcookie.html" class="function">setrawcookie()</a></span> function. </p> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.http-auth.html">HTTP authentication with PHP</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.sessions.html">Sessions</a></div> <div class="up"><a href="features.html">Features</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>