Magento – Magento isLoggedIn() always return false while customer is logged in

customerhelpermagento-1.9

I am new in Magento. Using Magento 1.9.2 version i create test.php file in Magento root i which write the code

include 'app/Mage.php';
Mage::app('default');
$customerName = Mage::helper('customer')->isLoggedIn();
var_dump($customerName);exit;

It always returning me false while i have logged in one customer in new tab. I just want to get data current logged in customer. It giving me null please help me sort out that problem.

Best Answer

You should use session for check is someone logged.

You can change 'name' to admin if you want check is someone logged into admin.
Solution found here:
https://stackoverflow.com/questions/13723166/magento-can-not-detect-if-customer-is-logged-in-or-not

require_once 'app/Mage.php';


umask(0);

Mage::app('default');

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

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

if($sessionCustomer->isLoggedIn()) {
  echo "Logged";
} else {
   echo "Not Logged";
}
Related Topic