User state custom pages - best way to assemble in php
I have a jqtouch website depending on if someone is logged in or not the pages change. At the moment I have a pretty ugly solution....
function page1()
{
$page1 = '<div>.........</div>';
return $page1;
}
function page2()
{
$page2 = '<div>.........</div>';
return $page2;
}
function page3()
{
$page3 = '<div>.........</div>';
return page3();
}
etc....
to load the page I do the following
echo page1() . page2() . page3();
or
echo page1() . page3();
Depending on what the user state is.
I need to mix and match pages so I have all the pages in one main page and only really want to run the sql withing those pages should they be needed.
effectively I ha开发者_JAVA技巧ve a stack of cards and I want to put them together in various ways with out disturbing the unrequired ones.
How would you assemble the pages?
Use templates:
In page1.php
<div>You are logged in!</div>
include_once("common2.php");
<div>Do you want to logout?</div>
In page2.php
<div>Please login first!/div>
include_once("common2.php");
<div><a href="#">Login Here</a></div>
In common.php
<div>This is common to all pages</div>
In common2.php
<div>
This is common to all pages but
it appears in the middle of the content of page1 and page 2
</div>
Then in your gateway
page you do this:
include_once("common.tpl");
if($userIsLoggedIn)
{
include_once("page1.tpl");
}
else
{
include_once("page2.tpl");
}
精彩评论