...

View Full Version : set cookie expiration



zorro
09-26-2003, 12:46 AM
I need to change the cookie expiration time to 1 year, but I'm confused about which line to change. I've checked several online tutorials, but I think they all assume I know too much. I think it may be this line, but can't find out what the numbers represent:
var expires_date = new Date(todays_date.getTime() + (days * 86400000));
Any help? Thanks!

Obviously, this is just partial code:

function Set_Cookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
if (Get_Cookie(name)) document.cookie = name + "=" +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

var today = new Date();
var zero_date = new Date(0,0,0);
today.setTime(today.getTime() - zero_date.getTime());

var todays_date = new
Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
var expires_date = new Date(todays_date.getTime() + (days * 86400000));

zorro
09-26-2003, 04:57 AM
OK folks, I am trying. Maybe if I try to answer my own question, someone will help. Even a YES or NO will help.

It's approximate of course, but what if I change this:
var expires_date = new Date(todays_date.getTime() + (days * 86400000));

to this:
var expires_date = new Date(todays_date.getTime() + (days * 1096056000086));

Would this be for about a year? What is this? milliseconds?

Philip M
09-26-2003, 08:24 AM
Yes, as you say, milliseconds.

So make it (1000 * 60 * 60 *24 * 365) to get one year expiry.

zorro
09-26-2003, 08:37 AM
Thanks very much for the post, but you are giving me too much credit, too, I think. It doesn't make since, to me to replace:

(days * 86400000)

with

(1000 * 60 * 60 *24 * 365)

Will the script understand this? I don't think like a programmer, more like a mechanic - seems like I'm replacing 2 items with 5 and to me, the script won't understand this. Can you explain?

glenngv
09-26-2003, 09:41 AM
isn't it that you just need to set the days variable to 365?

var days = 365;
var expires_date = new Date(todays_date.getTime() + (days * 86400000));

the 86400000 is equivalent to 1 day in milliseconds. So if you multiply any number with it, you'd get that number of days in msec.

look for the line that sets the days variable and change its value.

zorro
09-26-2003, 09:51 AM
Glenn,

I had failed to copy that line, but there is such a line in the script. This makes sense to me - thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum