我需要检查用户注册并获取您的信息,但都在同一个领域内,但Magento的结构之外的文件:/mymagento/islogged.php
require_once ('app/Mage.php');
Mage::app();
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
$sessionCustomer = Mage::getSingleton("customer/session");
if($sessionCustomer->isLoggedIn()) {
$customer = $sessionCustomer->getCustomer();
$telefono = $customer->getTelefonoMovil();
} else {
header('Location: '.ROOT.'customer/account/login/');
}
但是,这是行不通的,找不到会话。 我已阅读下列主题:
- Magento的会议不对外页面工作(同一域)
- Magento的客户/会话不工作
- 如何Magento的外部创建一个Magento的会议?
- 如何从Magento的外部访问的Magento用户会话?
- 检查外部网页Magento的登录
- 获取Magento的会话变量在另一页
最后我做了如下:
require_once ('app/Mage.php');
Mage::app();
// Define the path to the root of Magento installation.
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
// Obtain the general session and search for an item called 'customer_id'
$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/');
}
// Load the user session.
Mage::getSingleton('customer/session')->loginById($customerId);
$customerSession = Mage::getSingleton("customer/session");
// We verified that created successfully (not required)
if(!$customerSession->isLoggedIn()) {
header('Location: '.ROOT.'customer/account/login/');
}
// Load customer
$customer = $customerSession->getCustomer();
// We get cell phone
$telefono = $customer->getTelefonoMovil();