How do I use cookies across two different domains?

前端 未结 5 742
既然无缘
既然无缘 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条回答
  •  自闭症患者
    2020-11-27 05:44

    You don't, cookies are bound to a domain. There are restrictions on this and it's referred to as cross site scripting.

    Now, for some help to your problem. What you can do is create a script that helps bridge them.

    You can globally rewrite all links to your second site are going to need cookie information from the first site.

    You would save all the cookies from site-a to a database that they both can read, then programatically appending the cookie-id querystring on all of the links to site-b, then you lookup that cookie id and re-set the cookies under the new domain.

    There is a really good PHP database abstraction library (PHP ADODB) and it has a session sharing plugin that makes all of this a whole lot easier.

提交回复
热议问题