从Zend框架(另一个应用程序)获取Magento会话


Get Magento Session from Zend framework (Another Application)

我想从Zend Framework(另一个应用程序)获取Magento会话。我需要Zend框架中的应用程序验证管理员中的用户是否已记录(Magento)。我的Zend框架应用程序中有以下代码:

    // Initialize Magento
    include_once 'C:/xampp/htdocs/mymagento/app/Mage.php';
    // Initialize Magento
    Mage::app('default');
    // This initalizes the session, using 'adminhtml' as the session name.
    // Just ignore the returned Mage_Core_Model_Session instance
    Mage::getSingleton('core/session', array('name' => 'adminhtml'));
    // Get a singleton instance of the Mage_Admin_Model_Session class
    // This is just the 'admin' namespace of the current session. (adminhtml in this case)
    $session = Mage::getSingleton('admin/session');

    // Use the 'admin/session' object to check loggedIn status
    if ( $session->isLoggedIn() ) {
        echo "logged in";
    } else {
        echo "not logged in";
    }

响应都是"未登录"; 当我登录Magento Backend时。

会话仅为父域创建 - 从中启动Magento

的域。

我假设在您的情况下Magento和"另一个zend应用程序"是不同的域,这可能会触发问题。Magento和"另一个zend应用程序"都应该在一个父域上。例如:

(*.example.com | magento.example.com | anotherzendapp.example.com)。

发生此问题的另一个原因是另一个 zend 应用程序的自动加载。如果是这种情况,此解决方案应该会有所帮助:

$autoloaders = spl_autoload_functions();
$anotherZendApp = $autoloaders[0];
spl_autoload_unregister($anotherZendApp);
// YOU CODE
restore_error_handler();
restore_exception_handler();
spl_autoload_register($anotherZendApp);