Welcome! Log In Create A New Profile

Advanced

PHP Website Template

Posted by Brad_78160642 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
PHP Website Template
August 21, 2013 01:27PM
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";   ?>
Sorry, only registered users may post in this forum.

Click here to login