I have built a PHP login system which starts session before loading each page and checks if the user is logged in.
On my Protected page I have a include at the top that starts the session and the if statement as to load the page or not. And then a the bottom I have another include which is the else statement redirecting back to the login page. This works fine when in the page direct, but when included from elsewhere I get this error: Parse error: syntax error, unexpected $end
This is the code
Include 1:
<?php
session_start();
if ($_SESSION['username'])
{
?>
THIS IS THE PROTECTED CONTENT THAT GETS LOADED IF SESSION EXISTS
Include 2:
<?php
}
else
header ("location: index.php");
?>
I think this might be caused by splitting the curly braces on the statement into two PHP tags, the reason why I have done this is to load a whole page if the if statement is true, rather than leaving it in PHP and echoing each line of HTML seperate.
How can I resolve this? or is there a better way for me to split the IF/ELSE statement.
Thanks Danny