How to set a cookie for another domain

后端 未结 11 1927
一向
一向 2020-11-22 07:21

Say I have a website called a.com, and when a specific page of this site is loaded, say page link, I like to set a cookie for another site called b.com

11条回答
  •  天涯浪人
    2020-11-22 07:55

    You can't, at least not directly. That would be a nasty security risk.

    While you can specify a Domain attribute, the specification says "The user agent will reject cookies unless the Domain attribute specifies a scope for the cookie that would include the origin server."

    Since the origin server is a.com and that does not include b.com, it can't be set.

    You would need to get b.com to set the cookie instead. You could do this via (for example) HTTP redirects to b.com and back.

提交回复
热议问题