我有代码:
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;
但我总是得到
Mage_Core_Exception Object ( [_messages:protected] => Array ( ) [message:protected] => 无效的登录名或密码.
登录名和密码正确,我尝试了很多帐户,结果都一样.
Login and password is correct, I tried many accounts, with the same result.
如何正确登录?
<?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){
}
}
?>
这篇关于Magento 客户以编程方式登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
覆盖 Magento 配置Override Magento Config(覆盖 Magento 配置)
什么会导致 print_r 和/或 var_dump 调试变量失败?What would cause a print_r and/or a var_dump to fail debugging a variable?(什么会导致 print_r 和/或 var_dump 调试变量失败?)
如何在 magento 中以编程方式更新自定义选项?How to update custom options programatically in magento?(如何在 magento 中以编程方式更新自定义选项?)
管理页面上的 Magento 404Magento 404 on Admin Page(管理页面上的 Magento 404)
Magento - 从订单中获取价格规则Magento - get price rules from order(Magento - 从订单中获取价格规则)
Magento 更改产品页面标题以包含属性Magento Change Product Page Titles to Include Attributes(Magento 更改产品页面标题以包含属性)