开发者

Difference between Host and Domain in Cookie parameters PHP

Suppose I have two sess开发者_JAVA技巧ion cookies which looks like

First one

Name: d58ba4091c622661a0d46f03b412ac8b
Content: m9ciub2u3ig59638r43uqjb8e6
Host: www.example.com
Path: /
Send for: Any type of connection
Expires:Sunday, February 27, 2011 5:50:18 PM

and second one

Name: test
Content: kdfssdfb2ufdfjww3436detasd
Domain: .www.example.com
Path: /
Send for: Any type of connection
Expires:Sunday, February 27, 2011 5:50:18 PM

If you can see first one contain Host parameter and value and second one contain the Domain parameter. What is exact they do and what's the difference b/w them?

Thanks


According to comments to setcookie() function description, the difference is the following:

  • Host: www.example.com

is restricted to specified host, so this cookie will not be visible neither to entirely different domains, nor to subdomains. Such cookie is created if setcookie() parameter $domain is set to empty string:

setcookie($name, $value, time()+3600, $path, "");
  • Domain: .www.example.com

is restricted to specified domain, so this cookie will be visible to subdomains of specified domain (all domains like *.www.example.com). Such cookie is created if setcookie() parameter $domain is set to some domain:

setcookie($name, $value, time()+3600, $path, "www.example.com");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜