logo

Setting Future Expiring Cookies in IE

Here's a topical one for you. I was just about to implement a cookie-acceptance form on a Domino website that I look after for a customer when I thought I'd check it in IE (as all good developers should) first. Just because. You know. Even the simplest of changes aren't bound to work in IE.

And it's good job I did check too as my code worked in all browsers other than IE!! Typical.

My code was in a field on a Domino-based form. User's are given the option to "accept cookie use" by pressing a button. This POSTs the form back to the server, where a cookie is set to say they've accepted and it won't then ask them again.

The code in the field on the form looked like this:

cookieName:="ACMECookiesAccepted";
cookieValue:="TRUE";
cookieDomain:= "."+@Right(Server_Name ; ".");
maxAge:=@Text(60*60*24*7*52*2);
result:=cookieName + "="+cookieValue + "; Domain="+cookieDomain  + "; Path=/; Max-Age=" + maxAge;

@SetHTTPHeader("Set-Cookie"; result)

This sets a cookie that lasts for two years. Well, at least it does in most browsers. It turns our IE doesn't support the use of max-age. IE only accepts works with the (deprecated) "Expires" value, which has to be in a very specific GMT-based date format (like "Thu, 31-May-2012 14:37:12 GMT"). Damn it!

The code needed modifying to this:

expiresDate:=@Adjust(@Now; 2; 0; 0; 0; 0; 0);

expiresDateDayName:= @Replace(
        @Text(@Weekday(expiresDate)); 
        "1":"2":"3":"4":"5":"6":"7"; 
        "Sun":"Mon":"Tue":"Wed":"Thu":"Fri":"Sat"
);

expiresDateDay:=@Day(expiresDate);

expiresDateMonthName:= @Replace(
        @Text(@Month(expiresDate)); 
        "1":"2":"3":"4":"5":"6":"7":"8":"9":"10":"11":"12"; 
        "Jan":"Feb":"Mar":"Apr":"May":"Jun":"Jul":"Aug":"Sep":"Oct":"Nov":"Dec"
);

expiresDateGMT:=  expiresDateDayName + ", "+ @If(expiresDateDay<10; "0";"") +
        @Text(expiresDateDay) + " " + expiresDateMonthName + " " + @Text(@Year(ExpiresDate)) + " 23:59:59 GMT";

cookieName:="ACMECookiesAccepted";
cookieValue:="TRUE";
cookieDomain:= "."+@Right(Server_Name ; ".");
cookieMaxAge:= @Text(60*60*24*7*52*2);
result:=cookieName + "=" + cookieValue + "; Expires="+ expiresDateGMT + "; Domain="+cookieDomain  + "; Path=/; Max-Age=" + cookieMaxAge;

@SetHTTPHeader("Set-Cookie"; result)

Bloody IE!

Comments

    • avatar
    • Colm
    • Thu 31 May 2012 05:08 PM

    Internet explorer is a pox on the face of web development. The usual procedure for developing web sites/applications is:

    1). Develop site

    2). Test in FF, Chrome and Opera

    3). Minor tweaks needed

    4). Test in IE

    5). Harsh language

    6). Break site design so a multitude of hacks/workarounds can be added to cater for IE

    7). Add increased cost/development time to project

    Why anyone uses IE is beyond me.

      • avatar
      • Aaron Hardin
      • Fri 1 Jun 2012 08:55 AM

      They're called "M$" for a reason!

  1. A while back I gave up developing primarily in FF/Chrome and now mainly go with i.e. first.

    I find it easier to make i.e. compliant stuff work in other browsers than the other way round.

    Am I wrong here? I guess I'm busting some web standards, Jake will know.

    BTW I see Chrome has finally edged ahead of i.e. usage wise.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Thu 31 May 2012

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content