Making a simple navigation system using PHP
Yes, this is a simple layout, and yes, it’s very easy to make. But that’s the point. For all of you that are still using html to manage your pages, or just want a cleaner navigation system, this post is for you.
The main code of this layout is a short php code that can be used to call any page and thus eliminating the need to recode a layout for every singe page of the site.
Here is the main php code:
$abspath = ".";
$default = "main";
$error = "404";
$ext = ".php";
<p style="text-align: left;">clearstatcache();
$includestring = "";
$mainpage = $_GET['pg'];
$mainstring = $abspath."/".$mainpage.$ext;
if (!$mainpage) {
$includestring = $abspath."/".$default.$ext;
} elseif (ereg("\.\.", $mainpage) || substr($mainpage,0,2) == "./" || substr($mainpage,0,3) == "../") {
echo("Error..");
} elseif ($mainpage == "index.php") {
echo("Error: Cannot include self..");
} else {
if (file_exists($mainstring) && is_file($mainstring)) {
$includestring = $mainstring;
} else {
$includestring = $abspath."/".$error.$ext;
}
}
@include($includestring);
-$abspath is the path for where the files are stored
-$default is the default page that is called
-$error is the page that is called when a page doesn’t exist
-And $ext is the extension of the pages
No need to edit the code after this point, or at all really. To call your pages in a link just use:
<a href="?pg=name_of_page">link text</a>
And of course replace “name_of_page” with the name of your page, and “link text” with the text you want for the link. If you want to include a page in a folder, as long as it’s inside your $abspath, just use:
<a href="?pg=folder_name/name_of_page">link text</a>
And that’s about all there is to it, a preview can be found here, and you can download the simple layout here.

