tags:

views:

218

answers:

4

Why when set php cookie path to "/" doesn't work for every subdirs in the domain, but just for the current diretory.

cookie is set like: setcookie("name", "val", expire_time, "/");

it just doesn't want to work. Any help appreciated.

A: 

Setting the cookie path to / should make it available to the entire domain. If you set your cookie like that, and it isn't being sent, there is something else wrong.

Try using the Web Developer addon in Firefox. It shows you details on the available cookies. Maybe that can help you diagnose the problem.

Atli
+2  A: 

try including the domain parameter: setcookie("name","val",expire_time,"/",".domain.com"); // don't forget the prefixing period: .domain.com

that will enable all sudomains of "domain.com"

Janek
A: 

It works now.

I've deleted the cookie and set it up again a few times and works, because first it was set without the path parameter.

Thanks for your quick replies.

andreic160
No problem. Glad you got it working.
Atli
A: 

Are you testing on localhost? In that case, you need to pass null as the value for $domain.

troelskn
No localhost, but got it. Thanks.
andreic160