CascadiaPHP 2024


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 setcookie() or setrawcookie() function. Cookies are part of the HTTP header, so setcookie() must be called before any output is sent to the browser. This is the same limitation that header() has. You can use the output buffering functions to delay the script output until you have decided whether or not to set any cookies or send any headers.

Any cookies sent to server from the client will automatically be included into a $_COOKIE auto-global array if variables_order contains "C". If you wish to assign multiple values to a single cookie, just add [] to the cookie name.

For more details, including notes on browser bugs, see the setcookie() and setrawcookie() function.

add a note

User Contributed Notes 1 note

codewithsudeep at gmail dot com
1 year ago
// Example
// Setting a cookie
setcookie("usertoken", "noice", time()+20*24*60*60);
// 20 days = 20*24*60*60 seconds

setcookie("usertoken", "", time()-3600)
To Top