carhartl/jquery-cookie — Issue #40: cookie created with { path : '/' } is still only valid for the creation page
Author: phtrivier
Created: 2011-12-09 15:50:09+00:00
State: open

Hi !

I know this is a FAQ, and it's explained in the documentation that if you want a cookie to be valid on the whole site, it needs to be created with something like

$.cookies("foo", "bar", {
path : "/"
});

I'm in a situation where the cookie is created in a login page, where the user is redirected when they try to access a page like "/foo/bar/baz". But I want the cookie to be valid on all pages, so I obviously create it with the "path" : "/" options.

For some reason, when I open the Webdevelopper "View cookie information pane" in FF8, or when I use the settings screen to look at cookie details in Chrome, the cookie is displayed with a path like "foo/bar" (typically, the parent of the page I tried to access). So obvioulsy if I navigate to another page, the browser does not send the cookie.

I debugged the source of the plugin, and as far as I can tell the call
"""javascript
document.cookie = name + '=' + encodeURIComponent(value) + expires + path + domain + secure;
""""
is done with path being "; /", which is what I expect, isn't it ?

I have absolutely no clue as to what can be messing up with the cookies on the client side ; is there any thing I can have a look at ? Could the server somehow modifiy the cookie, so that on a subsequent request the browser feel the need to modify it ?

Any help welcome.