Subdirectoried Cookie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kirilisa
Forum Commoner
Posts: 28
Joined: Fri Dec 05, 2003 4:41 pm

Subdirectoried Cookie

Post by kirilisa »

So I made a very basic set cookie script, which sets a test cookie.

***********setcookie.php************
setcookie($cookie_name, $cookie_value, $cookie_expire, '/');

I then made a cookie test page which tests for the cookie existance and is in the same directory.

***********testcookie.php************
<? print_r($_COOKIE); ?>

testcookie.php works fine and shows that my cookie has been set. So then I copied testcookie.php into a subdirectory and went into that subdirectory and ran it - and my cookie wasn't set in there!

I thought that '/' indicated that the current directory and all subdirectories would have that cookie. Why doesn't my subdirectoried testcookie.php show my cookie?

-----------------------
I then tried putting my subdirectory in instead of '/' as an experiment.

setcookie($cookie_name, $cookie_value, $cookie_expire, $subdirectory);

When I did that, the testcookie.php showed no cookie both in the current directory and the subdirectory. I don't really understand the pathing argument of setcookie() perhaps...?
Post Reply