Cookies - set across multiple domains

后端 未结 5 1610
梦如初夏
梦如初夏 2021-02-01 22:01

My company has a setup as follows:

  • subdomain1.domain1.com
  • subdomain2.domain1.com
  • subdomain3.domain1.com
  • subdomain4.domain1.com
5条回答
  •  执笔经年
    2021-02-01 22:31

    This answer is a slightly different version of my answer on the question "Set cookie on multiple domains with PHP or JavaScript".

    Do what Google is doing. Create a PHP (or any other server language file) file that sets the cookie on all 3 domains. Then on the domain where the login is going to be set, create a HTML file that would load the PHP file that sets cookie on the other 2 domains. Example:

    
     
     
     Please wait..........
     
     
     
    
    

    Then add an onload callback on body tag. The document will only load when the images completely load that is when cookies are set on the other 2 domains. Onload Callback :

    
     
    
    
    

    Now cookies are set on the three domains.

    Source

提交回复
热议问题