我从外部网站登录magento时遇到问题。 我已经对它进行了研究,并在网上尝试了几个代码,但从我的外部网站登录后,它不会自动登录到magento网站。
这是我的登录表单。
<?php
if (isset($_POST['login'])) {
function validatePassword($password, $hash) {
$hashArr = explode(':', $hash);
switch(count($hashArr)) {
case 1:
return md5($password) === $hash;
case 2:
return md5($hashArr[1].$password) === $hashArr[0];
}
return false;
}
$apiUrl = 'http://magentowebsite.com/api/soap/?wsdl';
$apiUser = 'USER API';
$apiKey = 'PASSWORD';
if(isset($_POST['login'])) {
try {
$client = new SoapClient($apiUrl);
$session = $client->login($apiUser, $apiKey);
} catch (Exception $e) {
echo $e;
exit;
}
//Lookup customer record
list($customer) = $client->call(
$session,
'customer.list',
array(
array(
'email' => addslashes($_POST['login']['username'])
)
)
);
if(is_array($customer)) {
if(validatePassword($_POST['login']['password'], $customer['password_hash'])) {
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
//Log out any existing sessions
if(!$session->isLoggedIn()) {
$session->logout();
}
//Log user in
$login = Mage::getSingleton('core/app')->getRequest()->getPost('login');
$session->login($login['username'], $login['password']);
header('Location: http://www.magentowebsite.com/');
exit;
exit;
} else {
header('Location: http://www.myexternalloginsite.com?ref=invalid');
exit;
}
}
else {
header('Location: http://www.myexternalloginsite.com?ref=invalid');
exit;
}
}
}
?>
<form action="http://www.myexternalloginsite.com" method="post">
<div class="login_field">
<label for="login_username">Username</label>
<input id="login_username" type="text" value="" name="login[username]" />
</div>
<div class="login_field">
<label for="login_password">Password</label>
<input id="login_password" type="password" value="" name="login[password]" />
</div>
<div class="login_field">
<input type="submit" value="log in" />
</div>
</form>
表单效果很好,我的意思是它可以加载然后将我重定向到magento站点。但未以用户使用以前的凭据登录。我在这里失踪了什么?我需要在magento管理面板中更改任何配置吗?
谢谢