Forum Moderators: coopster

Message Too Old, No Replies

Reading Cookie expiry date

         

zendak

11:39 am on Jun 2, 2004 (gmt 0)

10+ Year Member



Is it possible to read the expiry date of a cookie?

The following only returns the value of the cookie:

echo $_COOKIE['somecookie'];

I wasn't able to find out from the manual if $_COOKIE is a multidimensional array from which keys other than the name can be read.

The purpose would be to be able to tell a user when a certain cookie will expire.

dcrombie

2:23 pm on Jun 2, 2004 (gmt 0)



No. Only the cookie name and value is sent from the browser to the webserver. Everything else is handled internally by the browser. I don't think event JavaScript can read the expiry date.

coopster

2:51 pm on Jun 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could set an additional cookie that is the expiry date, and check that.

victor

3:57 pm on Jun 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do it on one site -- ie tell the user the life of their cookie.

I do it by recording the cookie expiry info in the user record when I create the cookie.

But that isn't guaranteed -- I may have set the expiry date to creation date + 60, but the browser may be set to flush cookies on exit.

zendak

11:44 am on Jun 7, 2004 (gmt 0)

10+ Year Member



Thanks everyone,

I've been going through the original Netscape cookie specs meanwhile... Seems we're stuck with the workarounds you guys suggested.