views:

114

answers:

4

Hi,

I was wonder if you can delete a cookie at the beginning of the next day.

Lets say I log in to a website at 1:30pm and use it again throughout the day but at midnight or 1 minute past, in the new day, the cookie is removed.

Many thanks for any help, C

A: 

Give the cookie an appropriate expiry datetime.

Marcelo Cantos
A: 

You can let cookies expire on a given date / time. Have a look at the setCookie function here:

http://techpatterns.com/downloads/javascript_cookies.php

seanizer
A: 

Set the cookie expiration date accordingly. I am wondering what scripting language you're using, but its always possible to calculate and specify an absolute date. So if you started browsing on 2010-05-18 01:30 you can have the cookie expire at 2010-05-19 00:00. The math is fairly easy.

Salman A
+2  A: 

Yes - set an expiry time of midnight:

function midnight_cookie(name, value, path)
{
  var now = new Date();
  var expire = new Date();
  expire.setFullYear(now.getFullYear());
  expire.setMonth(now.getMonth());
  expire.setDate(date.getDate()+1);
  expire.setHours(0);
  expire.setMinutes(0);
  document.cookie = name+"="+value+"; expires=" + expire.toString() +"; path=" + path;
}
symcbean