在子域和域之间共享cookie

本文翻译自:Share cookie between subdomain and domain

I have two questions. 我有两个问题。 I understand that if I specify the domain as .mydomain.com (with the leading dot) in the cookie that all subdomains can share a cookie. 我理解,如果我在cookie中将域指定为.mydomain.com (带有前导点),则所有子域都可以共享cookie。

Can subdomain.mydomain.com access a cookie created in mydomain.com (without the www subdomain)? subdomain.mydomain.com可以访问在mydomain.com创建的cookie(没有www子域)吗?

Can mydomain.com (without the www subdomain) access the cookie if created in subdomain.mydomain.com ? 如果在subdomain.mydomain.com创建, mydomain.com (没有www子域)可以访问cookie吗?


#1楼

参考:https://stackoom.com/question/1FalM/在子域和域之间共享cookie


#2楼

The 2 domains mydomain.com and subdomain.mydomain.com can only share cookies if the domain is explicitly named in the Set-Cookie header. 如果在Set-Cookie标头中明确命名域,则2个域mydomain.comsubdomain.mydomain.com只能共享cookie。 Otherwise, the scope of the cookie is restricted to the request host. 否则,cookie的范围仅限于请求主机。 (This is referred to as a "host-only cookie". See What is a host only cookie? ) (这被称为“仅限主机的cookie”。请参阅什么是仅限主机的cookie?

For instance, if you sent the following header from subdomain.mydomain.com , then the cookie won't be sent for requests to mydomain.com : 例如,如果您从subdomain.mydomain.com发送以下标头,则不会将请求发送到mydomain.com

Set-Cookie: name=value
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值