开发者

Setting cookie path to "/" does not make cookie accessible to entire site

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

cookie is set like:

setcookie("name", "val", expire_time, "/");

It just doesn't want to work.


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"


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


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.


Late to the party, I know. But I just discovered that my issue was pretty stupid, but I'll post it for completion:

I was neglecting to add time() to the expires time on the cookie, so it was expiring immediately.

The expires time should be time() + seconds

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜