How to access Magento user's session from outside Magento?

后端 未结 3 1536
慢半拍i
慢半拍i 2020-11-30 08:19

Im trying to access the Magento customer session in another part of my website.

domain.com/shop/ <- Magento
domain.com/test.php

The shop

3条回答
  •  甜味超标
    2020-11-30 08:48

    The same issue was driving me mad. I worked through the following until the last item solved it:

    • Has the correct Mage store ID (current store) been set?
    • Are you using the same session path as Magento?
    • Are you using the same (sub)domain for cookie purposes?
    • Are you using HTTP or HTTPS both inside and outside Magento?

    If you've checked all the above, make sure you initialize a core "frontend" session on its own first like this:

    // Initialise the core "frontend" session
    Mage::getModel('core/session', array('name' => 'frontend'));
    

    Then you can access the customer/session like this:

    $customer = Mage::getSingleton("customer/session", array('name' => 'frontend'))->getCustomer();
    

提交回复
热议问题