Magento:手动登录不工作

时间:2015-10-12 12:14:32

标签: php magento

我需要手动登录已在其他页面登录的用户(使用已同步的userdata)。所以我尝试将登录数据发送到magento控制器并手动登录用户。登录脚本如下所示:

$customerId = $_GET['u'];
$password = $_GET['p'];
$localCustomer = Mage::getModel('customer/customer')
        ->getCollection()
        ->addAttributeToSelect('customer_id')
        ->addAttributeToFilter('customer_id', $customerNumber)
        ->load();
$customer = Mage::getModel('customer/customer')->load($localCustomer->getData()[0]['entity_id']);
umask(0);
ob_start();
session_start();
Mage::app('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton('customer/session');
$session->login($customer->getData('customer_id'), $password);
$session->setCustomerAsLoggedIn($customer);
header('Location: '.$forwardUrl);

这在Firefox和Chrome中运行良好,但出于某种原因,它不在Internet Explorer 11中,我似乎无法理解为什么。如果我在此之后查询来自客户/会话的数据,它们就在那里,但是一旦我导航到起始页面,我就不再登录了。只有在Internet Explorer中,才能与普通浏览器完美配合。

任何想法,提示,为什么会发生这种情况?我变得绝望了。

1 个答案:

答案 0 :(得分:0)

试试这个

<?php

function loginUser( $email, $password )

    require_once ("app/Mage.php");
    umask(0);
    ob_start();
    session_start();
    Mage::app('default');
    Mage::getSingleton("core/session", array("name" => "frontend"));

    $websiteId = Mage::app()->getWebsite()->getId();
    $store = Mage::app()->getStore();
    $customer = Mage::getModel("customer/customer");
    $customer->website_id = $websiteId;
    $customer->setStore($store);
    try {
           $customer->loadByEmail($email);
           $session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
           $session->login($email, $password);
    }catch(Exception $e){

    }


  } 
?>