设置特定子域的会话Cookie [英] Set session cookies for specific subdomains
问题描述
我有一个包含多个子域的网站,它们共享一个唯一的PHP会话cookie,以标识每个用户。我是通过简单地添加 session.cookie_domain ='.mydomain.com'
来完成此操作的,但是我想知道是否可以指定多个子域,以便cookie仅被发送到例如 www.mydomain.com
和 user.mydomain.com
,但不会出现在 images.mydomain.com
。
这可能吗?
I have a website with multiple subdomains, which share a unique PHP session cookie to identify each user. I did this by simply adding session.cookie_domain = '.mydomain.com'
, however I'm wondering if it's possible to specify more than one subdomain, so that cookies will only get sent to, for example, www.mydomain.com
and user.mydomain.com
but won't in images.mydomain.com
.
Would this be possible?
推荐答案
不,那将是2个单独的cookie。
No, those would have to be 2 separate cookies.
您必须创建一个像 sub.mydomain.com
这样的子域,并拥有一个像 www.sub.mydomain.com
等,如果要在其中隔离cookie,请为 .sub.mydomain.com
设置cookie。这样...
You would have to create a sub-domain like sub.mydomain.com
, have hosts like www.sub.mydomain.com
etc., and set cookies for .sub.mydomain.com
if you wanted to isolate cookies in that way...
这篇关于设置特定子域的会话Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!