Modifying a Cookie

suggest change

Change a cookie by sending it again with setcookie:

setcookie("user", "John", time() + 86400, "/"); // assuming there is a "user" cookie already

Cookies are part of the HTTP header, so setcookie() must be called before any output is sent to the browser.

The path and domain must match the existing cookie, or the browser stores a second cookie. secure, httponly, and samesite also identify the cookie in current browsers.

setcookie URL-encodes the value. PHP decodes it into $_COOKIE under the cookie's name. It does not create a variable with that name.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents