Forum Moderators: open

Message Too Old, No Replies

Annual cookie acting like a session cookie?

         

JAB Creations

4:59 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My cookie which is supposed to last a year is acting like a session cookie, it does not get more obnoxious then that.

document.cookie='bandwidth=4;path=/;time()+314496000;'

Whats wrong here?

John

moltar

5:12 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First of all you need an "expires=" keyword, and then you can't just specify number of seconds, you need to set it using the specific format:

var date = new Date(); 
date.setTime(date.getTime()+(365*24*60*60*1000));
var expires = "expires=" + date.toGMTString();

coopster

5:23 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Also, 314496000 = 3.64 days.

JAB Creations

5:24 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to keep this as simple as possible...

document.cookie='bandwidth=4;path=/;expires=314496000;'

This still does not seem to work. I want to avoid functions as much as possible.

I checked Opera and it said my cookie expired in 1969. ;)

John

moltar

5:44 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look, you can't pass number of seconds, you need to pass a valid GMT string.

The date string is formatted as:

Wdy, DD-Mon-YYYY HH:MM:SS GMT

This is based on RFC 822, RFC 850, RFC 1036, and RFC 1123, with the variations that the only legal time zone is GMT and the separators between the elements of the date must be dashes.

You can't argue with specifications - they are set in stone :)

JAB Creations

6:05 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



People who are not naturally gifted at programming should always be present when standards are created because they don't make sense half the time.

Ok so I'll just set my cookies to expire in 4,000 years. Anyone know what day of the week June 2nd, 6006 is?

John

coopster

8:30 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



LOL! Yes, the first time you dig into an RFC grab a pot of coffee and get ready for some great reading. Hey, at least the format is always the same though.

moltar

10:14 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think RFCs are really well written. Yes they are detailed, yes they are sometimes annoying to read, but it's for the purpose of clarity. They make sure to cover every single aspect possible to avoid confusion. Because with confusion come errors. And we don't want errors, do we? :)

JAB Creations

5:11 pm on Mar 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RFC =?

John