Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript cookie set on one page is not set on another page
    primarykey
    data
    text
    <p>I've tried two separate methods of setting and reading cookies using Javascript with the same consistent problem.</p> <p>The first time I visit the page in a fresh browser session and go through the page setting the cookie, the first page reports that it is setting the cookie successfully and redirects the user on to the next page. The next page checks for the cookie, doesn't detect it, and boots back to the first page. I go through the first page again and magically the second page detects the cookie is properly set.</p> <p>This is alright for testing but it's horrible end-user experience. I've used Mozilla's suggested code for handling cookies as well as the code on Quirksmode. I have the same result either way. I am setting JSON in the cookie for reference later.</p> <p>The page setting the cookie: /setCookie.php</p> <p>The page reading the cookie: /readCookie.php</p> <p>Code setting the cookie using Quirksmode code:</p> <pre><code>createCookie('userJSON',JSON.stringify(dat)); window.location="/readCookie.php"; </code></pre> <p>Code reading the cookie using Quirksmode code:</p> <pre><code>if( !readCookie('userJSON') ){ window.location="/setCookie.php"; } </code></pre> <p>Code setting the cookie using Mozilla code:</p> <pre><code>docCookies.setItem("userJSON",JSON.stringify(dat),null,"/"); window.location="/readCookie.php"; </code></pre> <p>Code reading the cookie using Mozilla code:</p> <pre><code>if( !docCookies.getItem('userJSON') ){ window.location="/setCookie.php"; } </code></pre> <p>JSON being stored in the cookie, tested as valid using jsonlint.com:</p> <pre><code>{ "first_name": "", "last_name": "", "email": "email@myDomain.test", "phone": "", "state": "CA", "barcode": "", "session_id": "1338398988873_4981", "guest_id": "", "event_id": "", "queue": "0", "SEND_MMS": false, "SEND_EMAIL": false, "location": "web" } </code></pre> <p>As I have not altered the Mozilla or Quirksmode code, links to the pages with their code are included here.</p> <p>Mozilla Cookies: <a href="https://developer.mozilla.org/en/DOM/document.cookie" rel="nofollow">https://developer.mozilla.org/en/DOM/document.cookie</a></p> <p>Quirksmode Cookies: <a href="http://www.quirksmode.org/js/cookies.html" rel="nofollow">http://www.quirksmode.org/js/cookies.html</a></p> <p>As you can see from the code, the path is being set to "/" so it should be valid on all pages within the domain. Any insight into this problem would be greatly appreciated.</p> <p>Again, this is only a problem the first time visiting the pages in a fresh browser session (I can reproduce it easily by exiting my browser, opening it up again, and visiting the pages), subsequent runs through these pages from the same browser session flow smoothly through these pages without being booted back to the setCookie.php page.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload