你好我在使用重定向问题表已提交后。 我使用的是简单的Ajax形式在一个div显示登录错误。
$(document).ready(function(){
$('#formlogin').on('submit', function (e) {
$.ajax({
type: 'POST',
url: 'login.php',
data: $(this).serialize(),
success: function(data) {
$('div#ack').empty().append(data);
}
});
e.preventDefault();
});
问题是提交成功并不重定向到“logged_in.php”后
这是PHP的登录。
if (empty($username) === true || empty ($password) === true) {
$errors [] = 'Please enter both username and password!';
} else if (user_exists($username) === false) {
$errors [] = 'We can not find the name. Have you registered?';
} else {
$login = login($username, $password);
if ($login === false) {
$errors [] = 'This user name or password is incorrect.';
} else {
$_SESSION['user_id'] = $login;
header('Location: logged_in.php');
exit();
}
}