How do I use cookies across two different domains?

前端 未结 5 752
既然无缘
既然无缘 2020-11-27 05:21

I need to share SSO information between two different domains with a cookie, can this be done in PHP and how?

5条回答
  •  Happy的楠姐
    2020-11-27 06:05

    Well, if your domains are just different subdomains you could do it in an easy way by creating a .yourdomain.com cookie. Then the cookie is passed along with all the requests across all the subdomains.

    It's not that simple if you want to share cookies between different domains as browsers treat it as a security risk.

    What is the exact example?

    In case of some software like Google Analytics and other tracking images, etc. you might be forced to use P3P headers to let browser know you don't care about security when sending your cookies. Then a browser requesting image gets a cookie as part of the response and also inspects P3P. If all is OK it saves the cookie on the hard drive and the next time you request an image that sits on your website (but is part of other domains page) the browser will send the cookie along. But I guess this does not help ;-)

    I have never used a cookie value across domains in a direct meaning of it.

提交回复
热议问题