set cookie to lower level directory??


#1

Hi all

I thought that by making the fourth setcookie() parameter “…/” it would make it available on the previous level directory, but alas not. How can this be done? It works fine to set it to a subsequent sub folder, or the entire domain, or the default value (just the current folder), but not for the next level up directory.

Any ideas? Thanks in advance.

p.s. I’ve also tried ‘…/…/dir’


#2

I am not 100% sure but I believe that the path is an absolute path (relative to the root of the webserver). So to specify a path for your cookie as “…/” you would be asking to set the path to a directory that is not a valid URL for the webserver.

Try specifying the path from the root of the webserver.

e.g.
Your current path is :
www.domain.com/dir1/dir2/dir3/index.php
and you want to set the cookie for dir2 instead of using :
setcookie(“TestCookie”, $value, time()+3600, “…/”,);
you could/should use
setcookie(“TestCookie”, $value, time()+3600, “/dir1/dir2/”,);

Good luck


#3

Thanks for that, I’ll try it. Using…

setcookie(“TestCookie”, $value, time()+3600, “/dir1/dir2/”,);

…does, however, assume that the cookie will be set in reference to the root folder, not from the current working directory, otherwise it would be trying to set it in dir1/dir2/dir3/dir1/dir2

Cheers