How to overwrite existing Cookie with new value in PHP?

Webdev picture Webdev · Feb 3, 2012 · Viewed 15.5k times · Source

I have been searching on how to overwrite a certain cookies value like for example in user's information. how can I call the cookie back to the client matched on the user's input. for the cookie to change its value?

Answer

Steve Buzonas picture Steve Buzonas · Feb 3, 2012

You can only overwrite cookies that you have access to modify. If you are setting a cookie yourself with setcookie() the same functionality will overwrite that cookie.

Cookies must be modified before any data is sent to the browser. The browser identifies a cookie and stores it based on headers sent from the server to the browser. The HTTP protocol will not accept header elements during transmission of the body.