ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

IE7 can't/won't read cookie on site homepage only

October 31, 2011 8:18am

Subscribe [3]
  • #1 / Oct 31, 2011 8:18am

    Clicked

    19 posts

    Version EE 2.2.2

    I have a problem with reading a cookie on the homepage of my EE2 site.

    This issue appears to be limited to IE7 (and poss IE6 - haven’t checked yet). IE8+, and all ‘proper’ browsers are not affected by this problem.

    As a user navigates around my site there is a custom cookie used to render some personal information for the user. The cookie name is like this: “myBrand_session” with myBrand repaced by the site name.

    The page loads an EE template, and then on ‘doc ready’ a script (JS) checks for the existence of the cookie and renders some additional data into the template. The jQuery cookie plugin is being used to check for the existence of cookies and to set/delete them as appropriate.

    In IE7, on every page of my site except the homepage, this cookie is present and is read perfectly - the page behaves as expected. On the site homepage however the cookie is not being read. If I look at the document the cookie is not even present in the page.

    I’ve taken everything out of my homepage template - it’s an empy <html><head></head><body></body></html> shell with only the calls to the relevant scripts. The issue persists.

    If I copy the stripped back homepage code to another template in the same template group it works properly and the user’s session cookie is detected and read etc.

    If I edit the template group so that the /index/ template is no longer the site’s homepage and then hit the /index/ template the cookie is detected and the page works.

    The issue is present when template caching is on for this particular template, and when template caching is switched off.

    This leads me to assume that EE is doing something differently with my template when it is the ‘homepage’ of the site - and this is somehow messing up the document’s cookies in IE7.

    Can anyone help? This has serious ramifications for my site. I need to run a load test using a specific piece of software than unfortunately requires IE7 to run. At the moment this IE7/cookie/homepage issue is preventing me from running the load tests I need to run.

    Looking forward to any help or advice that can be given,

    thanks

    Charlie

  • #2 / Nov 01, 2011 1:58am

    John Henry Donovan

    12339 posts

    Hi Charlie,,

    Are you getting any JavaScript errors on that page when you visit it?

    Is it possible for you to upgrade to the latest version of EE so we can troubleshoot from the same version?

    Can you show us the method you use in your template to check for cookies etc so we can try and replicate?

  • #3 / Nov 01, 2011 7:27am

    Clicked

    19 posts

    Hi John,

    No I’m not getting any JS errors. It’s as if the cookie simply doesn’t exist.

    I look for the query using the jQuery cookie script as follows:

    var sessionData = this.getCookie(this.sessionCookieName);

    on the homepage sessionData is null, everywhere else it has the contents of the cookie. I’m not convinced that the fault lies with the JS because on every other page, even in IE7, it all works perfectly.

    On the homepage if I alert/log the document’s cookie object in JS the session cookie is not present. Whereas the same alert/log on any other page, including a duplicate template that is not set as the site homepage, shows the cookie as present and correct.

    (Upgrading to the latest version of EE isn’t really an option at present as we have to keep our staging and live versions of this site as mirrored environments - and upgrading the live site’s EE version would mean taking it down for a period which I can’t do without notice, sign-off etc.)

  • #4 / Nov 03, 2011 9:19pm

    Dan Decker

    7338 posts

    Hi Clicked,

    Can you give us an idea about how you are setting the cookie? Are you also using JS to do that, or an particular add-on?

    Thanks,

  • #5 / Nov 09, 2011 12:37pm

    Clicked

    19 posts

    Hi Dan - thanks for your response.

    No I am not using any EE add-ons - the cookie is set by a custom javascript file that performs certain actions on each page after the DOM has loaded.

    It appears upon further testing that this issue is not limited to IE7. ExpressionEngine is killing these cookies on the site homepage in other browsers as well. (The problem wasn’t noticed until IE browser testing began because my JS uses localstorage where available before falling back to cookies.)

    As I detailed in my original post every other page on the site works fine - and the cookie magically ‘reappears’ if I navigate from the site homepage to some other page on my site when logged in.

    I’m really in need of some help on this issue - myself and two other developers have taken a long look at this problem over the last week and we can’t figure out why the homepage doesn’t have cookies available.

    Charlie

  • #6 / Nov 10, 2011 10:34am

    Clicked

    19 posts

    Hi guys,

    I’ve been able to reproduce this issue on 2 separate bare-bones installations of ExpressionEngine - version 2.2.2 and the latest version (2.3.1).

    This is happening on all browsers (tested on latest Chrome and FireFox):

    The 2.2.2 test site can be found here

    The 2.3.1 test can be found here

    Both test sites consist of the same template structure - a home page, page 1 and page 2. The homepage runs a script which looks for a cookie with the name ‘test’ and tries to alert its data. This is done using jQuery and the jQuery cookie plugin:

    // Home page
      var testCookie = $.cookie('test');
      alert('Cookie Data: '+testCookie);

    Page 1 sets the cookie:

    // Page 1
      if($.cookie("test", "foo")){
          alert('cookie set');
      }

    Page 2 is an exact copy of the home page.

    Page 1 successfully sets the cookie. Page 2 successfully reads and alerts the cookie data. The home page doesn’t. We would be really grateful if you guys could look into this as soon as possible - because of this problem visitors to our site in browsers without localStorage aren’t served any personalised data on the home page whatsoever…

    Thanks

     

  • #7 / Nov 10, 2011 7:45pm

    Dan Decker

    7338 posts

    Hi Clicked,

    If run the same “home” test on a plain html file at the root of your server, does it work? Are you setting any sort of cookie domain as part of the process? Also, would any of these cookie add-ons at Devot:ee offer you a solution?

    Cheers,

  • #8 / Nov 11, 2011 5:46am

    Clicked

    19 posts

    Hi Dan,

    Thanks for getting back to me. I have uploaded a static HTML version of the test to http://www.clickedprototype.co.uk/

    Without ExpressionEngine, the cookie is being read perfectly on index.html.

    I have tried with and without explicitly setting the domain on the EE tests with no change in in behaviour.

    Thanks for the suggestions - but an ExpressionEngine add-on is not going to help us I’m afraid - Cookies must be set and read via javascript, as we are serving all user-specific data through a custom javascript API to enable better caching of the ee templates and reduce the load on our servers…

    Cheers

    Steve

  • #9 / Nov 14, 2011 5:08pm

    Dan Decker

    7338 posts

    Hi Steve,

    Thanks for running these tests for us. After speaking with my cohorts here, we do believe that ExpressionEngine is doing something to mess with this. For instance, if you access your site’s “index template” directly, the cookie works properly: see here.

    At this point, we are going to escalate this to our Developers and get some deeper insight into the issue.

    Thanks for your patience!

  • #10 / Nov 14, 2011 7:22pm

    Robin Sowell

    13255 posts

    Not much experience w/setting cookies via js- but looks like it’s specifying a particular path- hence cookie is only active w/in that path.

    Try specifying the path a la path : ‘/’ - make sense?

  • #11 / Nov 15, 2011 6:32am

    Clicked

    19 posts

    Hi Robin - thanks for your reply - that is exactly the workaround we found last night!

    Setting path to ‘/’ resolves the issue across browsers on both our test rigs and on the original site we experienced the problem with.

    Charlie

  • #12 / Nov 15, 2011 9:29am

    Robin Sowell

    13255 posts

    😉  Good deal, glad you got it squared away!  Run into any more issues, just give us a yell.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases