好的,所以我有一个用于登录的重定向功能。继承人一些代码:
if ($sukces) {
$_SESSION['id'] = $row['id'];
if($_POST['location'] != '') {
header('Refresh: 1;url='.$_POST['location'].'');
echo message('You have logged in.<br>Press <a href="'.$_POST['location'].'">here</a> if you are not returned automatically.');
return false;
} else {
header("Location: /home");
}
} else {
// login failed
exit();
}
if($_POST['location'] != '') {
header('Refresh: 1;url='.$_POST['location'].'');
} else {
header("Location: /account");
}
<form action="?page=login" method="post">
<input type="hidden" name="location" value="<?=isset($_REQUEST['redirect']) ? htmlspecialchars($_REQUEST['redirect']) : ''?>">
E.g:
http://localhost/?page=login&redirect=%2Fforum%2F%3Faction%3Dpost%26boardid%3D1
问题是如果您输入错误的登录凭据,位置输入字段的值将变为空。但是,如果您输入错误然后输入正确,您将不会被重定向。这是为什么?如何保留重定向网址?