Passing along session in Magento to different domains

In some of our larger Magento EE (Enterprise Edition) setups we have Multiple stores that have different domains. One of the challenges with stores on different domains is sharing sessions. Luckily magento has some built in functionality to be able to pass along a session id as a SID as a query param. This works in conjunction with the users local cookies to make sure the cart is persistent between stores. There are a few ways to go about it but I found that the solution below works pretty well for us.

First off I think it’s a good idea to take a look at this page for reference. The link below will go over some of the params you can pass to the “Mage:getUrl();” method.

Welcome back. You read the link above right? Welp if you didn’t it’s cool. I like code examples too. So take a look below.


Below you’ll see I am using Mage:getURL(); I am passing along a few parameters.

    • The store ID I am linking to (so I get the proper base url. ) Be sure it replace $YOUR_STORE_ID with your proper store ID as an integer
    • Our session ID I grab from the core/sessions singleton
    • lastly I also append the actual store “slug” to the url as well just to be sure we switch our store.
$session_id = Mage::getSingleton("core/session")->getEncryptedSessionId(); // get our session

echo Mage::getUrl( '/', array('_store' => $YOUR_STORE_ID,// pass along a store id IF NEEDED
'_query' => array('SID' => $session_id ), //make sure we append our session
'_store_to_url' => true ) ); // lastly add store to our url if needed

Aaron Ware

For nearly 20 years Aaron Ware has worked with leading brands, start-ups and everyone in between to develop innovative, highly interactive, feature-rich websites, and online apps.

| @aaronware