Get cookie expiration
Is it possible to read the expiration time of a cookie using php? When I print_r($_COOKIE)
output:
Array
(
[PHPSESSID] => 0afef6bac83a7db8abd9f87b76838d7f
[userId] => 1232
[userEmail] => user@email.com
[firstName] => user
[lastName] => user
)
So I guess it $_COOKIE
doesn't have an expiration time, is it possible with some other function?
a source to share
no, there is no way.
The browser uses cookie parameters (path, expiration, etc.) only to determine whether the cookie is sent or not, but none of these parameters are sent back to the server.
don't think of cookie as an element of the $ _SESSON array, but as an HTTP header. It always helps.
a source to share
Or you can use the time () function on the cookie value so that you only need one cookie and can retrieve the data. PHP code will look like this:
setCookie('cookiename', time(), time() + 86400);
This way you will have a cookie expiration in one day, and by getting its value you can know when it will expire with something like this:
86400 - (time() - $_COOKIE['cookiename']);
a source to share