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!
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.
Reply
They're called "M$" for a reason!
Reply
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.
Reply