How do I use cookies across two different domains?

前端 未结 5 767
既然无缘
既然无缘 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:55

    If you have two sites using the same domain and would like to share cookies between them, set something like this in your settings.php file for each domain:

    ini_set('session.cookie_domain', '.EXAMPLE.com');
    

    Be sure you include the leading '.' before the domain name, or it won't work.

    This allows users to maintain login status between any sites configured for domain-wide cookies.

    This can also have negative side effects, so don't do this unless you're familiar with all the cookies involved for the sites you want to share cookies between.

提交回复
热议问题