Well the index.php is the problem, and in so many ways.
First that "if" is setting "$SESSION['status']" to equal "logged" not checking if it equals "logged". You could change that to
if ($_SESSION["status"] = false)
{
header('Location:login.php');
}
and you would still be redirect to login.php. Basically the "if" is checking if you can set that value to "$_SESSION["status"]" so no matter what value is after the equal (=) it will return true and run the code in that "if".
I assume you want it to be this
if ($_SESSION["status"] == "logged")
{
header('Location:login.php');
}
But the "if", in your original post, sets "$_SESSION['status']" to "logged" meaning when the "if" (original post) redirects to index.php then index.php will redirect to login.php. So no matter what your current code will land you on the login.php.
So probably the if should be
if (isset($_SESSION["status"]) && $_SESSION["status"] != "logged")
{
header('Location:login.php');
}
I added the "isset" to avoid notice level errors
Side note, you don't need that "return true;" in your "if".