Run Magento Session Into An External Site



Sometimes if we are working with the Ecommerce platform then client wants to use the Magento as Backend and frontend in the Framework like the Codeignitor and the Zend. Suppose you want to use Magento backend in framework like as zend framework then the below code will enable you to use all Magento's power into your custom website
<?php

	require_once ( "/var/www/your-magento-directory/app/Mage.php" ); //Include Magento application
	umask(0);

	Mage::app("default"); //Initialize Magento

	// You have two options here,

	Mage::getSingleton("core/session", array("name" => "frontend")); //"frontend" for frontend session


	Mage::getSingleton("core/session", array("name" => "adminhtml")); //"adminhtml" for admin session

?>

You have done! Now you can use the internal classes and functions of Magento into your custom Framework website. i.e. If you want to check whether a customer is logged in or not by checking the Magento session.

<?php
	$session = Mage::getSingleton("customer/session");

	if($session->isLoggedIn())
	{
	    echo "Logged in";
	}else{
	    echo "Not logged in";
	}
?>

Now you can use all the functionality of the Magento in your Framework. Enjoy the Magento Coding.