[thelist] any JS cookie experts out there?

Roger Ly rogerly at bareviking.com
Tue Dec 17 12:02:01 CST 2002

>I am trying this:

>document.cookie = "groom=<?=$groom?> expires=Wdy, 01-Mon-2010 12:12:12
> GMT";

Try this:

document.cookie = "groom=<?=$groom?>; expires=Wdy, 01-Mon-2010 12:12:12
GMT; path=/";

If I am not mistaken, you should a) have a semi-colon after the cookie
name/value parameters, and b) if you omit the path, it will default the
cookie to only be available to files located in the subdirectory of the
file in which you set the cookie.

For example, if you set a cookie in
http://www.mydomain.com/blah/setcookie.php, you would only be able to
read that cookie on pages located in the blah subdirectory (and its
subdirectories).  So, if you tried to read the cookie in
http://www.mydomain.com/test.html or
http://www.mydomain.com/foo/test.html, it wouldn't be there.

If you set path=/, it will set the cookie in the domain root, and you
should be able to retrieve it from anywhere in your domain.


More information about the thelist mailing list