php setcookie域 [英] php setcookie domain
问题描述
有些应用程序,不是由我写的,而不是在PHP中,为域www.domain.com创建一个cookie。
Some application, not written by me, and not in PHP, creates a cookie for the domain "www.domain.com".
那个cookie。所以在php我做了:
I am trying to replace that cookie. So in php I did:
setcookie('mycookie','mydata',time() + 2*7*24*60*60,'/','www.domain.com', false);
但是,结果Cookie是为域.www.domain.com创建的,请注意点。
However the resulting cookie is created for domain: ".www.domain.com", note the dot "." ahead of the domain.
因此它不会替换它,它会创建另一个cookie。
我可以做什么?
So it doesn't replace it, it creates another cookie. What can I do?
推荐答案
问题也出现在这里:
http://php.net/manual/en/function.setcookie.php
请参阅jah的注释:如果要将cookie限制到单个主机,请将domain参数提供为空字符串
See comment by "jah": If you want to restrict the cookie to a single host, supply the domain parameter as an empty string
您也可以尝试使用.domain.com作为域名。后面的点将允许domain.com的所有子域的cookie,并且可以覆盖www。 - cookie,但我将首先使用上述解决方案。
You could also try ".domain.com" as the domain. The trailing dot will allow a cookie for all subdomains for "domain.com" and could overwrite the "www."-cookie, but I'll go with the above solution first.
这篇关于php setcookie域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!