最近,由于没有“明显”的原因,我的登录表单开始重定向到我网站的 404 页面,我在任何地方都看不到原因。
<?php echo '<form action="http://' . $_SERVER['SERVER_NAME'] . '/login" method="post">'; ?>
<li><input type="text" name="username" placeholder="Username"></li>
<li><input type="password" name="password" placeholder="Password"></li>
<li><input type="submit" value="Login"></li>
</form>
然而由于某种原因,它仍然会重定向到 404 页面,而<?php echo'http://' . $_SERVER['SERVER_NAME'] . '/login
实际上是相同的页面。除了用户成功登录之外,没有其他重定向,它转到不同的页面。我只是不明白是什么原因造成的,其他人可以解决为什么吗?
编辑:我的 .htaccess 是
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?page=$1
验证码:
<?php
if(empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) === true || empty($password) === true) {
$errors[] = 'You need to enter a username and password.';
} else if (user_exists($username) === false) {
$errors[] = 'We can\'t find that username. Have you registered?';
} else if (user_active($username) === false) {
$errors[] = 'You haven\'t activated your account!';
} else if(strlen($password) > 32 ) {
$errors[] = 'Password to long.';
}
$login = login($username, $password);
if($login === false){
$errors[] = 'That username/password combination is incorrect.';
}else{
$_SESSION['user_id'] = $login;
header('Location: ' . $_SERVER['SERVER_NAME'] . '/?msg=1');
exit();
}
}
if(empty($errors)===false){
?>
<h1>We tried to log you in, but....</h1>
<?php
print_r($errors);
} ?>