The MooTools docs state: * In order to share the Cookie with pages located in a different path, the Cookie.options.domain value must be set.
Read The Friendly Manual :P On Mar 10, 1:21 pm, woomla <[email protected]> wrote: > If I have a cookie in a subdirectory, this cookie is read from even > when I'm in the root. When I write the cookie, the cookie's path is > the root. So reading and writing goes to different cookies (same name, > different path). > > Here's how: > > When I browse to a directory on my webserver it automatically loads > the index.html file located in that directory. > Example:http://mywebserver/CookieTest, > no slash at the end. > > If i set a cookie and read it, it is changed every time. > If you view the cookie information (with i.e. FireCookie), you see the > cookie (in the root) beeing changed. > This is good. > > Now if I browse to:http://mywebserver/CookieTest/, the same > index.html file is loaded. > If I set a cookie and read it, it is changed every time. > If you view the cookie information (with i.e. FireCookie), you see the > cookie (in the /CookieTest/) beeing changed. > This is good. > > Now if you go back tohttp://mywebserver/CookieTest, the same > index.html is loaded. > Now if you set the cookie, the cookie in the root (/) is set, but the > cookie in the directory (/CookieTest/) is read. > Now there's a difference between reading and writing the Cookie. > This is *not* good. > > Maybe it's not good practice to use a url without /. Should I have my > webserver append it always? If so, then how? > > I think the problem boils down to Cookie.read that does a match and > finds the 'wrong' cookie. I'll try to see if I can get more > information on this. > > I don't know if this is a bug, but it did surprise me to. > > I've tried to setup a mooshell example, but mooshell always puts the > slash at the end, so it doesn't work. > But you can find the test at:http://www.mootools.net/shell/3UQkR/2/. > > Here's a sample index.html file. You have to put this in a directory > on your webserver i.e. CookieTest together with mootools.js. > > ============ index.html ================ > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <script src="/CookieTest/mootools.js" type="text/javascript"></ > script> > > <meta http-equiv="content-type" content="text/html; > charset=windows-1250"> > <meta name="generator" content="Woomla"> > <title>Cookie Test</title> > <script type="text/javascript"> > > function info(text) > { > $('info').appendText(text); > $('info').grab(new Element('br')); > } > > function getTheCookie() > { > var value = Cookie.read('cookietest.key'); > info('get: ' + value); > } > > function setTheCookie() > { > var value = new Date().getTime(); > info('set: ' + value); > Cookie.write('cookietest.key', value, {'duration': 3600}); > getTheCookie(); > } > > window.addEvent('domready', function () > { > $('set').addEvent('click', setTheCookie); > getTheCookie(); > }); > </script> > > <style type="text/css"> > <!-- > #info > { > border:1px dashed black; > width:90%; > padding:5px; > } > //--> > </style> > </head> > <body> > > <button type="button" id="set">set</button> > <br /> > <br /> > <div id="info"></div> > > </body> > </html>
