Sunday 31 May 2015

How to get customer session in external file Magento ?

Hi sometime we need to access the customer session in nexternal file and with the below code you can access


<?php
// Include Magento application
require_once ( "path_to_your_magento/app/Mage.php" );
umask(0);

// Initialize Magento
Mage::app();

// You have two options here,
// "frontend" for frontend session or "adminhtml" for admin session
Mage::getSingleton("core/session", array("name" => "frontend"));

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

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

No comments:

Post a Comment