How do you update a cookie in PHP?

Cookie picture Cookie · Jun 27, 2011 · Viewed 78.2k times · Source

If I call setcookie() two times with the same cookie name, I get two cookies created.

How do you update an existing cookie?

Answer

Omar Alahmed picture Omar Alahmed · Jun 24, 2013

You can update a cookie value using setcookie() function, but you should add '/' in the 4th argument which is the 'path' argument, to prevent creating another cookie with the same name.

i.e. setcookie('cookie_name', 'cookie_value', $exp_date, '/');