Setting a Cookie
suggest changeA cookie is set using the setcookie() function. Since cookies are part of the HTTP header, you must set any cookies before sending any output to the browser.
Example:
setcookie("user", "Tom", time() + 86400, "/"); // check syntax for function params
Description:
- Creates a cookie with name
user - Value of the cookie is
Tom - Cookie will expire in 1 day (86400 seconds)
- Cookie is available throughout the whole website
/
Further optional arguments, not passed in this call, include the domain, secure (HTTPS only), and httponly (hidden from JavaScript).
A created or modified cookie can only be accessed on subsequent requests (where path and domain match), because
$_COOKIEis not populated with the new data immediately.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents