加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – Magento客户端以编程方式登录

发布时间:2021-07-06 05:22:34 所属栏目:大数据 来源: https://www.jb51.cc
导读:我有代码:@H_403_1@ @H_403_1@ function loginUser( $email, $password ){ /** @var $session Mage_Customer_Model_Session */ $session = Mage::getSingleton( 'customer/session' ); try { $session-login( $email, $password ); $session-setCustomerAsL

我有代码:@H_403_1@

@H_403_1@

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;

但我总是得到@H_403_1@

Mage_Core_Exception对象([_messages:protected] => Array()[message:protected] =>无效的登录名或密码.@H_403_1@

登录和密码是正确的,我尝试了很多帐户,结果相同.@H_403_1@

我该如何正确登录?@H_403_1@

解决方法:@H_403_1@

<?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){

    }


  } 
?>
@H_403_1@

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读