Say I have a PHP script that creates a cookie that expires 10 days from now. Is there any way to use PHP to update the value and maintain the same expiration date?
For example, say my cookie is created today with a value of “foo” and expires on 3/13/10. Two days from now, I want to change the value to “bar”. Can I still have the cookie expire on the thirteenth or am I forced to either expire the cookie immediately or extend it another 10 days?
It’s not possible.
If you examine the HTTP specification (or watch HTTP headers using Firebug), you’ll find the browser doesn’t send back the expiry date to the server, only the name and value.
A way to do this (I’m sure there are better ways) is to set another cookie to store the original expiration date…