the182guy
Apr 7th, 2007, 07:00 AM
Im trying to avoid putting my login code on every page that needs authentication.
Is it possible to do something like have an include with an if statement which is left open so the rest of the page can exist inside my open else{, then at the end i will include a foot that just contains the } closing tag for the if?
heres my include
<?
//check login
if(!$logged_in){
echo("<p><strong>Error</strong><br />You need to be logged in to access this page. Click <a href='login.php'>here</a> to login</p>");
}else{
?>
So my page looks like:
<html>
blah
blah
<h1>Welcome</h1>
<? include("..assets/login_check_head.php"); ?>
THIS IS THE PROTECTED PAGE CONTENTS
<? include"..assets/login_check_foot.php ?>
blah
blah
</html>
But it throws an error saying unexpected $end in the include.
Any ideas? Or I will have to just insert this code into every page that requires login.
Cheers
Is it possible to do something like have an include with an if statement which is left open so the rest of the page can exist inside my open else{, then at the end i will include a foot that just contains the } closing tag for the if?
heres my include
<?
//check login
if(!$logged_in){
echo("<p><strong>Error</strong><br />You need to be logged in to access this page. Click <a href='login.php'>here</a> to login</p>");
}else{
?>
So my page looks like:
<html>
blah
blah
<h1>Welcome</h1>
<? include("..assets/login_check_head.php"); ?>
THIS IS THE PROTECTED PAGE CONTENTS
<? include"..assets/login_check_foot.php ?>
blah
blah
</html>
But it throws an error saying unexpected $end in the include.
Any ideas? Or I will have to just insert this code into every page that requires login.
Cheers