NickNo NickNo - 6 months ago 17x
PHP Question

In PHP how to get time/date when cookie was set/created?

How to get the cookie's birthday/time in PHP?

The cookie itself contains other data, so was wondering if there is a way to get the exact date and h:m:s when it was created without having to create a second cookie just to hold that information?

I searched but too much interference with the other keywords: set, time, cookie, date that's showing answers, but not to this question.


What you can do is to create an array, serialize that array to a string and store the serialized string inside the cookie:

$mycookieArray = array('cookiedata'=>'some data','creationTime'=>new DateTime());
$mycookiedata = serialize($mycookieArray);

Then, everytime you want to load the correct you have to unserialize the array from the cookiedata:

$mycookieArray = unserialize($mycookiedata);