这是问题所在:我正在使用脚本在 Magento 中创建一个用户,并尝试登录该用户(如果他/她已经存在)。
try {
// If new, save customer information
$customer -> firstname = $firstname;
$customer -> lastname = $lastname;
$customer -> email = $email;
$customer -> password_hash = md5($password);
if ($customer -> save()) {
echo $customer -> firstname . " " . $customer -> lastname . " information is saved!";
$customer->setConfirmation(null);
$customer->save();
} else {
echo "An error occured while saving customer";
}
} catch(Exception $e) {
// If customer already exists, initiate login
if (preg_match('/This customer email already exists/', $e)) {
$customer -> loadByEmail($email);
$session = Mage::getSingleton('customer/session');
$session -> login($email, $password);
echo $session -> isLoggedIn() ? $session -> getCustomer() -> getName() . ' is online!' : 'not logged in';
}
}
脚本回显“用户在线!”,但是当我转到主页时,它向我显示登录按钮,就好像我没有登录一样。我如何登录用户?