Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get cookie expiration date / creation date from javascript? [duplicate]

Is it possible to retrieve the creation or expiration date of an existing cookie from javascript? If so how?

like image 903
Nir Avatar asked Jul 18 '10 08:07

Nir


People also ask

How do I check my cookies expiry date?

If you are using Chrome you can goto the "Resources" tab and find the item "Cookies" in the left sidebar. From there select the domain you are checking the set cookie for and it will give you a list of cookies associated with that domain, along with their expiration date.

Which cookie has expiration date in Javascript?

This code defines a function, setCookie(). This function will create a cookie with the name “username”, value “Max Brown” with an expiration date of 30 days from the time it was created.

How do you set the expiry period for a cookie object?

Just set the expires parameter to a past date: document. cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; You should define the cookie path to ensure that you delete the right cookie.

Do Web cookies have an expiry date?

Cookies can expire. A cookie with no expiration date specified will expire when the browser is closed. These are often called session cookies because they are removed after the browser session ends (when the browser is closed). Cookies with an expiration date in the past will be removed from the browser.


1 Answers

It's impossible. document.cookie contains information in string like this:

key1=value1;key2=value2;... 

So there isn't any information about dates.

You can store these dates in separate cookie variable:

auth_user=Riateche;auth_expire=01/01/2012 

But user can change this variable.

like image 194
Pavel Strakhov Avatar answered Oct 11 '22 14:10

Pavel Strakhov