NAVIGATION SYSTEM
Navigation System DylanJ [ 30/05/2007 ]

This tutorial will produce pages with nice urls like (site.com/?id=page) Although this is not SEO friendly, it is however, much more developer friendly.
So lets get down to business. This is a pretty straight forward copy + paste tutorial. I only hope you have a look at and maybe learn something while you viciously copy and paste this onto your site.

<?php
$lol = "id"; // Change this if you please :)
$get = stripslashes($_GET['id']);
if (!isempty($get)) {
 //Filters out ./ so that you can't include files outside of where we want to include them :D|-<
 //Sure there are probably better ways to do this but this gets the job done.
 while ( $get[0] == '.' || $get[0] == '/' || $get[0] == '' ) {
  if ($get[0] == '.'){
  $get = ltrim( $get, '.' );
  }
  if ($get[0] == '/'){
  $get = ltrim( $get, '/' );
  }
  if ($get[0] == ''){
  $get = ltrim( $get, '' );
  }
 }

 //use "folder/" . $get . ".php"; if you would like to include from a folder that is not in the same directory as this file.
 $fname = $get . ".php";
 if ( file_exists( $fname ) ) {
  include( $fname );
 } else {
  echo "File not found!";
 }
} else {
 //This is the default page to include.
 include "news.php";
}
?>

The above code will include whatever.php (site.com/?id=whatever) onto the page that it has been pasted on.

If you find bugs let me know.
©2008 Dylan Johnston - <3 Joseph Rouse for the Hosting.