Access Magento session from external site

In: Magento, PHP on 09.02.2011 by Relja Damnjanovic

So, there is a simple way to access the running Magento session from outside the installation folder. The magic happens here:
$mageFilename = realpath(â??mymagentoshop/app/Mage.phpâ??);
require_once( $mageFilename );

Mage::getSingleton(â??core/sessionâ??, array(â??nameâ?? => â??frontendâ??));
$session = Mage::getSingleton(â??customer/sessionâ??);

   echo â??LOGGED INâ??;
   echo â??NOT LOGGED INâ??;
The line 5 presents the Magento initialization, and from there you can call any Magento core API functions and procedures. In order for session to work properly (as one) in both sites, you need to retrieve it, and that is exactly what is done on the lines 6 (for the core session) and 7 (for the customer session). Later in our example we're checking whether the customer is logged in or not, but you can do whatever you want! Oh yes, on more thing - Use SID on Frontend setting in the Magento admin (System -> Configuration -> Web -> Session Validation Settings) MUST be set to YES, otherwise it won't work.