Forum Moderators: coopster

Message Too Old, No Replies

Cookie time remaining.

Can it be retrieved

         

Matthew1980

7:58 pm on Feb 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello people of webmaster world,

Could someone point me in the right direction, I would like to know if once you set a cookie and specify a time limit on it, is there a method of working out how long is left remaining before it expires?

Reason I ask is so that a message can be displayed saying something along the lines of: Warning Cookie expires tomorrow!

Cheers,

MRb

rocknbil

9:26 pm on Feb 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, not directly.

- You set a cookie's name, value, path, and expiration time in the browser.

- On next request of the site from the browser, the browser sends the cookie name and value only as a header. Expiration date/time is not sent.

The way you would do this is set two cookies: your cookie and one something like "MY_SITE_C_EXPIRE" with the value of the cookie being the expiration date/time.

Then you can read THIS cookie to do the math on your alert. Be sure to set and get both of them at the exact same time so they always stay synchronized.

Alternatively, you could just store the time in a DB as soon as it's set, and update it whenever the cookie is set. Either way.

Warning Cookie expires tomorrow!


Unless this is a limited time offer sort of thing, there's not a whole lot of benefit to this. Most people don't even know what a cookie is, seeing such a message might prompt them to remember Uncle Bob telling them cookies are evil, and be the trigger to go disable them. I'm exaggerating (or am I) but you get the point.

Cookies should be managed transparently, for example, as someone logs in and visits a site, the expiration should automatically be updated with each page request, expiring only after period of inactivity. In the "limited time offer" scenario, it should be worded like "You have until tomorrow to take advantage of this deal" - one of the marketer's favorites, call to action.

Matthew1980

9:32 pm on Feb 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Rocknbil,

It's always good to get another perspective, It never dawned on me to use another cookie or even a DB reference, thanks for the pointer, I will now go and *adjust* the code to suit.

Cheers,

MRb