为什么Magento在使用客户/会话后删除了我的前端cookie?

时间:2015-03-04 02:08:06

标签: magento cookies nginx session-cookies hhvm

我正在使用Nginx和HHVM,我也使用自定义php文件与Magento进行交互。

当我运行任何PHP文件时,前端cookie设置正确,购物车也能正常工作。

然而,无论何时我使用:

$session = Mage::getSingleton( 'customer/session' );
$session->login($login, $pass);
$session->setCustomerAsLoggedIn($customer);

前端cookie被移除。

问题:为什么这样,我该怎么做才能解决它?

设置: enter image description here

完整示例:

include_once('../app/Mage.php');
    ob_start();
    umask(0);
    Mage::app();
    Mage::getSingleton('core/session', array('name'=>'frontend'));
    $login = $v[0]; //username as email
    $pass  = $v[1]; //user password
    try {
        $customer = Mage::getModel("customer/customer");
        $customer->website_id = Mage::app()->getWebsite()->getId();
        $customer->loadByEmail($login);

        $session = Mage::getSingleton( 'customer/session' );
        $session->login($login, $pass);
        $session->setCustomerAsLoggedIn($customer);

    } catch(Exception $e) {
        $returnJson['success']  = false;
        $returnJson['error']    = $e;
    }

2 个答案:

答案 0 :(得分:1)

我们通过添加HHVM ini设置解决了这个问题:

hhvm.server.allow_duplicate_cookies = 0

更多信息:https://github.com/facebook/hhvm/issues/2758

答案 1 :(得分:0)

可能没有关联,但为什么在登录之前加载客户,并且您永远不会检查登录功能是返回true还是false。您还手动将客户设置为已登录,如果用户/通行证正确,则在login()函数内执行此操作。我基本上会将整个try..catch部分改为:

try {
    $session = Mage::getSingleton( 'customer/session' );
    if (!$session->login($login, $pass)) {
        throw new Exception("Authentication failed");
    }
    $customer = $session->getCustomer();
    // more stuff?
} catch(Exception $e) {
    $returnJson['success']  = false;
    $returnJson['error']    = $e;
}

由于懒惰原因,显然没有经过测试/校对。 :)