I have some code to log how many password attempts have been tried that looks like this:
<?php
/* Access denied */
$_SESSION['error'] = "invalidlogin";
if (isset($_SESSION['tries']))
{
if ($_SESSION['tries'] == 5)
{
//TODO: Redirect somewhere nicer and more descriptive
header("location:/index.php");
}
else
{
$_SESSION['tries']++;
}
}
else
{
$_SESSION['tries'] = 0;
}
header("location:/login.php");
?>
I know it is counting up to five and then stopping cuz I tested it by echoing $_SESSION[‘error’] on login.php
PHP never redirects when it hits
header("location:/index.php");
But it always keeps going and then redirects to
header("location:/login.php");
How can I get PHP to redirect as soon as it hits the index.php redirect?
Do I just set a boolean after the index.php redirect and check it on the login.php redirect?
EDIT: To clarify, I have already defined a session_start(); don’t worry about that.
1 Answer