My PHP code to Display "Please Login" to users that are not logged in doesn't display anything it will show the user their information when they are logged in but now when they aren't here is my code:
<?php
session_start();
if (!$_SESSION['logged'])
{
header("Location: http://www.westbournegames.co.uk/login/login.php");
exit;
echo "Please login";
exit();
}
?>
It's because you have a header redirect and exit();
The file never reaches the line:
echo "Please login";
A user that is not logged in will enter the if
branch. You should have used !empty($_SESSION['logged']
to avoid a PHP notice which produces output.
Then the browser is redirected by the "header" call and the script exits. It can never reach your "Please login" output.
To show this you must remove the header()
and exit calls before echo.
I suggest changing $_SESSION['logged'] to $_SESSION['views'] like this: $_SESSION['views']=1;
<?php
session_start();
if ($_SESSION['views']!=1) {
header("Location: http://www.westbournegames.co.uk/login/login.php");
}
?>