Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out the expiry date of cookie using javascript [duplicate]

I use functions for creating and reading cookies from quirksmode.org/js/cookies.html. I set also days to expire. I would like to find out cookie's expiry date ... so I can tell visitor how many days he/she must wait until something is possible again == until cookie is automatically erased.

thanks thanks

like image 750
Adriana Avatar asked Jul 21 '09 14:07

Adriana


2 Answers

Hmm, there doesn’t seem to be an easy way to do this. JavaScript can only access the name/value pairs rather than the additional info that can be set in a cookie.

After some searching, the closest thing to a solution I could find (technically it is a workaround) is that if you really need to have the expiration date of a cookie, what you can do is to store it in another cookie. When you formulate the expiration date, set it as the expiration date of your target cookie, and the value of another cookie.

For example, set NAME=BOB;expirationdate and NAME_EXP=expirateiondate;expirationdate

like image 140
Synetech Avatar answered Oct 16 '22 11:10

Synetech


It is not possible to get this information.

All you can access client-side is the document.cookie property, a single string composed of name-value pairs. The other details are not accessible to the client.

like image 26
Andrzej Doyle Avatar answered Oct 16 '22 12:10

Andrzej Doyle