View Full Version : Enhanced Navigation (page.php?page=bla)

08-10-2005, 09:05 AM
Well, i realise there are probably many of these scripts avaliable in the tutorials section but i gauruntee none of them are like mine. I posted this script a while back in reply to someones question on these forums and no-one really gave feedback. I use it on many of my sites and it hasn't really aged, very usefull.

The script

* Enhanced Nav v1.01 by arkin [@] dsl [.] pipex [.] com
* More from http://www.arkin.org.uk
$page = Array();

// Edit these vars or leave as is.

$page['home'] = "home"; // Replace this with the default page.
$page['error'] = "404"; // Replace this with the 404 page, can be home.php also or even $page['home'].
$page['format'] = ".php"; // This will be the format of your page so ?page=bla will be bla.php.
$page['trig'] = "page"; // The trigger used so ?page=bla.

// Do not edit below.

if (empty($_GET[($page['trig'])])) $pg = $page['home'].$page['format'];
elseif (!file_exists($_GET[($page['trig'])].$page['format'])) $pg = $page['error'].$page['format'];
else $pg = $_GET[($page['trig'])].$page['format'];


Explanation begins..

So, what does it do? Its a highly configurable navigation script, as mentioned above, it takes your configured values and uses them to advantage you making you look professional and knowledgable.

The configuration..

$page['home'] = "home";
^^ Replace this with the default page, i.e. the home/front page for when no page is specified.
$page['error'] = "404";
^^ Replace this with the 404 page, the page that is displayed when the page requested does not exist, this can be set to $page['home'] if you just want it to return to the front/home page.
$page['format'] = ".php";
^^ This is the format of the page files, so if your pages are [page.pg.php] you would put .pg.php. I stick to just plain .php.
$page['trig'] = "page";
^^ This is the nice part, you can change the ?page=bla part of the script here so you can have whatever you want, you could even have ?page-content-load=hehe.

The script workings..

if (empty($_GET[($page['trig'])])) $pg = $page['home'].$page['format'];
^^ This checks if the $_GET['<page trigger>'] value is empty.. i.e. page.php?<page trigger>=bla, and if it is it continues to set the $pg variable to the homepage.

elseif (!file_exists($_GET[($page['trig'])].$page['format'])) $pg = $page['error'].$page['format'];
^^ This checks if the $_GET['<page trigger>'] page even exists or if the user is trying to access a page that doesn't work, if it doesn't the $pg variable is set to the error page as configured above.

else $pg = $_GET[($page['trig'])].$page['format'];
^^ This is for when the other 2 'if' criteria's aren't met. Basically if the page is being requested and it actually exists, it sets the $pg variable to the page being requested not forgetting the page format variable on the end

^^ Finally, this includes the page file to be displayed using the variable we have set above ($pg). Make sure you place the script where you want the content to go and not at the top otherwise the content will be displayed at the very top and cut up all your design.


For those who may question or wonder...

The dot operator or whatever its called simply joins 2 variables.

$x='12'; $y='13';
// $x is 12, $y is 13.
// $z is 1213

Well, thanks for reading my tutorial, it was an experience for me writing it, hope it at least helps one person because then i know my goal has been achieved.

Feedback would be nice

08-31-2005, 16:29 PM
so you made it?good work on coding then!