In my module i have a php file which is called by an Ajax Post, after a user has clicked on a link.
Now i need the customer-ID of that user who has clicked on this link.
require_once("../../../../../Mage.php");
umask(0);
Mage::app();
Mage::getSingleton('customer/session')->isLoggedIn()
Returns false at the same time at my phtml file with the same code it Returns true. I have tried other ways like
Mage::getSingleton('core/session', array('name' => 'frontend'));
if((Mage::getSingleton('customer/session')->isLoggedIn())) {
$productPriceString = "true";
} else {
$productPriceString = "false";
}
or even
define('ROOT',Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));
if(isset($coreSession['visitor_data']['customer_id'])){
$customerId = $coreSession['visitor_data']['customer_id'];
} else {
header('Location: '.ROOT.'customer/account/login/');
}
Mage::getSingleton('customer/session')->loginById($customerId);
$customerSession = Mage::getSingleton("customer/session");
if(!$customerSession->isLoggedIn()) {
header('Location: '.ROOT.'customer/account/login/');
}
But the result was always the same. So my question how can i get the id or even the _Customer object.
Thanks
EDIT
$session= Mage::getSingleton("core/session");
The result in my phtml file is object(Mage_Core_Model_Session)#125 (8)
But the result in my external php file is object(Mage_Core_Model_Session)#145 (8)
Best Answer
I have runned this script and it's working. It provides me the customer id. Before you run it, delete the
cache
andsession
folders under youvar
folder