Recently, for no 'apparent' reason, my login form started to redirect to my website's 404 page, and I don't see the cause anywhere.
<?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>
Yet for some reason, it still redirects to the 404 page, when <?php echo'http://' . $_SERVER['SERVER_NAME'] . '/login
is the exact same page. Apart from when the user is successfully logged in, there is no other redirecting, which goes to a different page. I just don't see what's causing this, can anyone else work out why?
EDIT: My .htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?page=$1
Authentication code:
<?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);
} ?>