I am writting a small project, a page where non registered users can access only few pages, registered ones to other few, and some of the registered ones to others. It's for a game, so only these playing a 'match' would have access to the latter. Furthermore, there will be some pages for us, the admins (secret pages). This is the structure:
$Public_Path = '/public_html/public/';
$Private_Path = '/public_html/private/';
$Secret_Path = '/public_html/secret/';
I pass everything through /public_html/index.php and include the files from there. I thought it would be better to have all the include and redirect in one place instead of scattered around at the beginning of each file. The thing is, code starts to get messy in here, and there's still many more options to add. Is there a schema that simplifies it? This is how my code looks right now:
// Some extra code goes here
// If an unregistered user tries to go anywhere he shouldn't
if (!file_exists($Public_Path . $Url . '/index.php') && empty($User))
header ('Location: /login/');
// PUBLIC. Load the public pages
if (file_exists($Public_Path . $Url . '/index.php'))
include $Public_Path . $Url . '/index.php';
// SECRET. Only for admin
else if (file_exists($Secret_Path . $Url . '/index.php') && in_array($User->email, $Admins))
include $Secret_Path . $Url . '/index.php';
// PRIVATE. Load the template and include private pages
else if (file_exists($Private_Path . $Url . '/index.php'))
{
if ($UrlArray[0] != 'games' && $User->game == 0)
header ('Location: /games/');
if ($UrlArray[1] == 'save')
include $Private_Path . $Url . '/index.php';
else
{
$Page = $Private_Path . $Url . '/index.php';
include $Include_Path . 'template.php';
}
}
// 404. Nor public nor private nor secret
else
header ('Location: /error/404');
Note: I know the limitation of only being able to access index.php
with this, I imposed that myself.
My question is, how can I order this code in some fashion that allows me to add much more functionality but increasing only a little the complexity? How to reduce the latter?