PDA

View Full Version : Are session cookies in JavaScript path sensitive?


WA
07-12-2002, 12:42 PM
Hi:
Anyone know if session only cookies are sensitive to the directory path in which they're called? I was under the impression it was only for persistent cookies. For example, lets say I call the statement:


document.cookie="popup=yes"

on the root path of my site http://www.javascriptkit.com. Is that cookie now also accessible on the page http://www.javascriptkit.com/subdir?

Someone suggested to me recently I had to use:


document.cookie="popunder=yes;path=/"

in order for a session only cookie to be accessible anywhere within a site, and I thought I'd seek some clarification on this.

Thanks,

joh6nn
07-12-2002, 02:35 PM
according to the Guide, the default for a cookie, is the direcory it was created in, and all of its subdirectories. if you want a cookie to be available throughout the entire site, then you probably ought to use ' path=/" ', even if you're creating it in the root directory.

Soldier Bob
07-12-2002, 02:45 PM
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q223799

and

ftp://ftp.rfc-editor.org/in-notes/rfc2965.txt

my firewall doesnt allow me to see this since its on ftp.

What I can tell so far though, is that there isnt a standard per say for this... So the question may be moot, and one would just use what works now.

-S. Bob

BrainJar
07-12-2002, 04:07 PM
The expiration date should not affect the cookie's path setting. The only difference between a "persistant" cookie and a "session" cookie is that the former has an explicit expiration date while the latter doesn't so the browser will delete it when closed.

The cookie path defaults to the path in the URL where it's set. Using path="/" should make it available to all pages on the site no matter where you set the cookie.

One thing to consider is the cookie domain. If your site is accessible via www.example.net, example.net and subdomain.example.net and you want to share a cookie between them, you should set the cookie domain to ".example.net".

WA
07-12-2002, 10:36 PM
Ok thanks guys. I ask this because people had emailed me about how one of JavaScriptKit.com's popunder window script (http://www.javascriptkit.com/script/script2/popunder.shtml) kept popping up even though the feature to pop up only once per session was on. I never inputted the path, which I guess is actually necessary.