This question already has an answer here:
I've made a login page and a logged page. The PHP code for the login page is:
<?php
session_start();
include 'functions.php';
if(isValid()){
header('Location: logged.php');
exit;
}
?>
and the code for the logged page is:
<?php
session_start();
include 'functions.php';
if(!isValid()){
header('Location: login.php');
exit;
}
?>
There is nothing before this code. After the code there is the login form in the login.php page and some informations in the logged.php page.
The isValid() function is correct, as I have tested it with an isvalid.php page that returns 1 when a user is correctly logged and 0 if there is no user logged or the informations saved in the session are wrong.
If I login with the form in the login.php page I can see all the informations in the logged.php page. If I than try to return to login.php, I am redirected to logged.php.
If I am not logged in and I try to access to logged.php the output is a blank page, without any redirect to the login.php page. PHP should redirect me to the login page!
I've seen in another discussion suggesting to debug if there is an output somewhere with headers_sent() function.
When I put a debug code like this
<?php
if(headers_sent())
echo "TRUE";
in the first line it returns TRUE in the logged page, nothing in the login page.
What's the problem?
</div>