我使用下面这个代码登录并重定向到帐户页面从外部Magento的帐户页面:Magento的:登录并重定向到
<?php
include('store/app/Mage.php');
Mage::app();
if($_POST && $_POST['login']['username'] && $_POST['login']['password']){
$email = $_POST['login']['username'];
$password = $_POST['login']['password'];
$session = Mage::getSingleton('customer/session');
try {
$log = $session->login($email, $password);
$session->setCustomerAsLoggedIn($session->getCustomer());
$customer_id = $session->getCustomerId();
$send_data["success"] = true;
$send_data["message"] = "Login Success";
$send_data["customer_id"] = $customer_id;
Mage::getSingleton('customer/session')->loginById($customer_id);
Mage_Core_Model_Session_Abstract_Varien::start();
}catch (Exception $ex) {
$send_data["success"] = false;
$send_data["message"] = $ex->getMessage();
}
}else {
$send_data["success"]=false;
$send_data["message"]="Enter both Email and Password";
}
echo json_encode($send_data);
?>
,然后从那里我将AJAX请求文件,我使用此代码:
if(data.success){
window.location = "http://domain.com/store/customer/account/"
}
但它始终显示用户注销,虽然我确实得到正确的客户ID以及成功。
你能告诉我我的代码中缺少什么吗?因为我能够获取客户名称,但仍然在我访问商店时显示用户仍然未登录。 – atif
我认为您没有完全登录,只调用会话存储信息(创建浏览器登录会话并存储在magento会话)有更多的原因。首先你必须使用会话开始。其次,你必须设置存储并且必须有管理会话,加载magento核心会话控制器。等..只是使用功能在我的答案,它会工作... – Martin
我确实收到消息“..用户loged作为用户名”,但仍然当我试图访问商店帐户页面,它将我重定向到登录页面。 – atif