PDA

View Full Version : cookies dissapper



NickNameDrive
06-04-2010, 04:52 PM
I've set cookies for browser session, simple document.cookie='bla=bla;' and nothing else. All browsers seem to get it right. So if I brows files withing same directory (site.com/folder1) everything's fine and bla=bla but whenever i change the directory (site.com/folder2) cookie dissapear.

Anybody knows why is that? And how to work around it, so to keep bla=bla for the entire browser session through entire site? Thank you!

djr33
06-05-2010, 12:59 AM
I'm not sure how to do this in Javascript (google should be able to tell you though), but I've done the same thing with PHP.

Cookies have optional other parameters and there are two relevant here: 1. path, 2. domain.

Cookies are only available locally unless you specify a greater area. If you set this cookie on your main index page then it will be available throughout the site, but if you set it within a subdirectory only within that. A value of / will select the site's root and it will work anywhere.

Cookies never work across different domains, but you can use .example.com to allow all possible subdomains (including the default) so that the users remains logged in (or whatever) across the various domains.

NickNameDrive
06-05-2010, 07:33 PM
yes, problem solved, path=/ was needed!