1

我正在使用的代码如下

public function loginUser($email, $password){
   $session = Mage::getSingleton('customer/session');

    try {
        $log = $session->login($email, $password);
        return $log;
     } 

    catch (Exception $ex) {
        return false;
    }
 }

它返回 1 但未登录浏览器,当我刷新页面时它不会设置为登录用户

4

1 回答 1

5

我认为您需要额外致电Mage_Customer_Model_Session::setCustomerAsLoggedIn()

public 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 true;
    }
    catch( Exception $e )
    {
        return false;
    }
}
于 2012-10-16T10:49:02.303 回答