2013-04-02 25 views
2

我需要檢查用戶是否已註冊並獲取您的信息,但都在同一個域中但在Magento的結構之外的文件中:/mymagento/islogged.phpMagento會話從外部頁面(相同的域名)

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/'); 
} 

但它不起作用,找不到會話。我已閱讀下列主題:

回答

2

最終我一樣如下:

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(); 
相關問題