I'm getting ready to start building a brand new web site for a client. I've traditionally set up sites with a master index page that pulls components together.
Links are set up in the site similar to, index.php?page=detail.
Is this a good approach to setting up site structure and hierarchies? This seems to work well when directories have multiple pages linking to others within it's own directory. But, seems like a bit much if a directory only contains the index.php. If there is only the index, do you just remove the switch?
Any recommendations on if I should keep doing what I'm doing or is there a better way?
index.php
session_start();
if(!isset($_COOKIE['token'])) {
header('Location: /store/account/index.php');
}
require_once('/root/to/assets/config.php');
require_once(LIBRARY_PATH . '/dbConnect.php');
$link_id = db_connect('mydb');
$allowedPages = array('default', 'detail', 'list');
$page = (isset($_GET['page']) && $_GET['page'] != '' && in_array($_GET['page'], $allowedPages)) ? $_GET['page'] : '';
switch ($page) {
case 'list' :
$myid = (!isset($_SESSION['myId']) ? header('Location: /store/account/index.php') : (int)$_SESSION['myId']);
$catId = (!isset($_GET['catId']) ? '0' : (int)$_GET['catId']);
$content = 'list.php';
$pageTitle = 'PRODUCTS';
break;
case 'detail' :
$myid = (!isset($_SESSION['myId']) ? header('Location: /store/account/index.php') : (int)$_SESSION['myId']);
$productId = (!isset($_GET['productId']) ? '1' : (int)$_GET['productId']);
$catId = (!isset($_GET['catId']) ? '1' : (int)$_GET['catId']);
$content = 'detail.php';
$pageTitle = 'DETAILS';
break;
default :
$footer = 'ON';
$myid = (!isset($_SESSION['myId']) ? header('Location: /store/account/index.php') : (int)$_SESSION['myId']);
$catId = (!isset($_GET['catId']) ? '0' : (int)$_GET['catId']);
$content = 'default.php';
$pageTitle = 'STORE';
}
require_once(TEMPLATES_PATH . '/content.php');
content.php
<?php
require_once(LIBRARY_PATH . '/doProcess.php');
require_once(TEMPLATES_PATH . '/header.php');
require_once($content);
require_once(TEMPLATES_PATH . '/footer.php');
?>