Magento Session from external page (same domain)

前端 未结 1 852
醉话见心
醉话见心 2021-01-07 04:21

I need to check that a user is registered and get your information, but all in a file within the same domain but outside the structure of Magento: /mymagento/islogged.php

相关标签:
1条回答
  • 2021-01-07 04:41

    In the end I did as follows:

    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();
    
    0 讨论(0)
提交回复
热议问题