共享本地存储/Cookies跨不同域名

huangapple go评论66阅读模式
英文:

Share localstorage/Cookies across the different domain

问题

我有一个域名 ab.example.com,想要在不同子域名示例 xyz.example.com 之间共享相同的本地存储/cookies。

我尝试使用 post message 函数来共享,但它不起作用。

请帮助我解决这个问题,提前感谢!

英文:

I have a domain ab.example.com and want to share the same localstorage/Cookies across different subdomain example xyz.example.com

I have tried to share by post message function but its not working.

kindly help me solve this problem thanks in advance mate.

答案1

得分: 0

Domain 属性

Domain 属性指定了哪些主机可以接收一个 cookie。如果服务器没有指定 Domain,浏览器会默认将域设置为设置了 cookie 的同一主机,不包括子域。如果指定了 Domain,则始终包括子域。因此,指定 Domain 比不指定它的限制性更小。但是,当子域需要共享关于用户的信息时,指定 Domain 可以很有帮助。

例如,如果你设置 Domain=mozilla.org,那么 cookie 可用于像 developer.mozilla.org 这样的子域。

英文:

Domain attribute

The Domain attribute specifies which hosts can receive a cookie. If the server does not specify a Domain, the browser defaults the domain to the same host that set the cookie, excluding subdomains. If Domain is specified, then subdomains are always included. Therefore, specifying Domain is less restrictive than omitting it. However, it can be helpful when subdomains need to share information about a user.

For example, if you set Domain=mozilla.org, cookies are available on subdomains like developer.mozilla.org.

huangapple
  • 本文由 发表于 2023年7月3日 22:33:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605742.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定