Developed this very basic PHP website template that will load different page content depending on the value of the
$_SERVER['QUERY_STRING']. So you don't have to write the header and footer into each page. Will work on a menu that shows the correct page as selected.
Looking forward to hearing some thoughts.
Language: PHP
<?php
// SETS $PAGE TO URI QUERY STRING IF NOT QUERY STRING IS NULL WILL SET $PAGE TO HOME
function set_page(){
$page = $_SERVER[';QUERY_STRING';];
if ($page == null OR $page == ""){
$page = "home";
}
return $page;
}
// CHECK IF $CURRENT_PAGE IS IN $PAGES ARRAY, IF NOT SET TO 404
function check_page($current_page, $pages){
$page_exists = 0;
foreach ($pages as $page) {
if ($page == $current_page){
$page_exists = 1;
break;
}
}
if ($page_exists == 0){
$current_page = "404";
}
return $current_page;
}
// SETS $CURRENT PAGE BY CALLING FUNCTIONS
$current_page = set_page();
$pages = array("404", "home", "contact"); // NEED TO NAME ALL PAGES IN THIS ARRAY
$current_page = check_page($current_page, $pages);
// INCLUDE YOUR PARTS
include "header.php";
include "$current_page.php";
include "footer.php";
?>