duanjian4331 2014-03-18 16:43
浏览 51
已采纳

Magento客户以编程方式登录

I have the code:

function loginUser( $email, $password )
{
    /** @var $session Mage_Customer_Model_Session */
    $session = Mage::getSingleton( 'customer/session' );

    try
    {
        $session->login( $email, $password );
        $session->setCustomerAsLoggedIn( $session->getCustomer() );
        return 1;
    }
    catch( Exception $e )
    {
        return $e;
    }
}

$test = loginUser("login","password");
echo "test";
print_r($test);
die;

but I always get

Mage_Core_Exception Object ( [_messages:protected] => Array ( ) [message:protected] => Invalid login or password.

Login and password is correct, I tried many accounts, with the same result.

How can I log in correctly?

  • 写回答

2条回答 默认 最新

  • douba8758 2014-03-19 05:34
    关注
    <?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){
    
        }
    
    
      } 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳