View Full Version : Cookie only working in one directory.

11-09-2006, 04:37 AM
I have a cookie set with these (very limited) parameters

setcookie ('username2', $username);
Currently if I call that via PHP
echo $_COOKIE["username2"];
, it only works in my "/login/" directory and not my main directory.
What addl parameters do I need to add to that so it will work everywhere?

(I bet this is something very simple)

Edit: Tried
setcookie('username2', $username, '/', 'MyWebsite.com'); didn't work.

11-09-2006, 09:19 AM
which directory is it being set it try

$value = "Test cookie";
setcookie("TestCookie", $value, time()+60*60*24*30); /* expire in 30 days */
setcookie('TestCookie', $value, time()+3600, '/', '.mysite.com'); /* expire in 1 hour and set for all directory's on your web server and all subdomains*/

11-09-2006, 02:36 PM
alright, that works..

but I've been having trouble finding out how to set the time syntax to expire at end of session without not including it..

11-09-2006, 03:03 PM
just leave it out?


nothing between the commas?

11-10-2006, 12:16 AM
See if I do

setcookie ('username2', $username, , '/', '.mysite.org');

I get

Parse error: syntax error, unexpected ',' on line 44

11-10-2006, 12:45 PM
setcookie ('username2', $username, '', '/', '.mysite.org');

there needs to be info to tell php your not limiting it
if you leave
setcookie ('username2', $username, , , '.mysite.com');
its not gonna know the directory or time to set
make sense?

11-10-2006, 02:18 PM
oops ... Rafiki is right ...

I think I forgot the ,' ',