« Back to Index

[Set same cookie on multiple domains]

View original Gist on GitHub

Tags: #cookie #multiple #domains

Reference: http://subinsb.com/set-same-cookie-on-different-domains/

The way Google does this is by creating a server-side script that sets the cookie on all the domains.

On the domain where the login occurs, create a intermediary page that would load the server-side script that sets a cookie on the other two domains.

i.e. the user authenticates, and are redirected to /processing

In that page you would add an onload callback onto the body tag.

The document will only load when the images have completely loaded (i.e. the cookies are set on the other two domains).

<!-- https://www.domain1.com/processing -->

<html>
 <head>
  <script>
   function loadComplete(){
    window.location="https://www.domain1.com/user/settings"; // page to redirect user once they're authenticated
   }
   </script>
 </head>
 <body onload="loadComplete()">
 	Please wait..........
 	<img src="https://www.domain2.com/setcookie.php?user=jwt"/>
 	<img src="https://www.domain3.com/setcookie.php?user=jwt"/>
 </body>
</html>