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?

+2


a source to share


3 answers


Only the name and value are sent to the server, so there are no other cookies.



You can just reset the cookie if you want to extend its duration - it's just a few bytes in the response, so it doesn't matter.

+5


a source


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.

+1


a source


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']);

0


a source







All Articles