我需要检查用户是否已注册并获取您的信息,但所有文件都位于同一域中的文件中,但不在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 Session not working in external page (same domain)
> Magento customer/session not working
> How do I create a Magento session outside of Magento?
> How to access Magento user’s session from outside Magento?
> Checking for Magento login on external page
> Get magento session variable in another page
解决方法:
最后我做了如下:
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();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。