<HTML ><HEAD ><TITLE >Cookies</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Features" HREF="features.html"><LINK REL="PREVIOUS" TITLE="HTTP authentication with PHP" HREF="features.http-auth.html"><LINK REL="NEXT" TITLE="Handling file uploads" HREF="features.file-upload.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="chapter" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="features.http-auth.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="features.file-upload.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="features.cookies" >Chapter 17. Cookies</A ></H1 ><P > PHP 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 <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A > function. Cookies are part of the HTTP header, so <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A > must be called before any output is sent to the browser. This is the same limitation that <A HREF="function.header.html" ><B CLASS="function" >header()</B ></A > has. You can use the <A HREF="ref.outcontrol.html" >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 > Any cookies sent to you from the client will automatically be turned into a PHP variable just like GET and POST method data, depending on the <TT CLASS="literal" >register_globals</TT > and <TT CLASS="literal" >variables_order</TT > configuration variables. If you wish to assign multiple values to a single cookie, just add <SPAN CLASS="emphasis" ><I CLASS="emphasis" >[]</I ></SPAN > to the cookie name. </P ><P > In PHP 4.1.0 and later, the <TT CLASS="literal" >$_COOKIE</TT > auto-global array will always be set with any cookies sent from the client. <TT CLASS="literal" >$HTTP_COOKIE_VARS</TT > is also set in earlier versions of PHP when the <TT CLASS="literal" >track_vars</TT > configuration variable is set. </P ><P > For more details, including notes on browser bugs, see the <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A > function. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="features.http-auth.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="features.file-upload.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >HTTP authentication with PHP</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="features.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Handling file uploads</TD ></TR ></TABLE ></DIV ></BODY ></HTML >