



(5 ratings)
Written in php4, works in php5, mostly so you can view the source and attempt at understanding how it works.
/*--- Configuration ---*/
$page = Array();
// Edit these vars or leave as is.
$page['home'] = "home";
// Replace this with the default or main page.
$page['error'] = "404";
// Replace this with the 404 page, can be 'home' 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 (!ctype_alpha($_GET[($page['trig'])])||
!file_exists($_GET[($page['trig'])].$page['format'])) {
$pg = $page['error'].$page['format'];
} else {
$pg = $_GET[($page['trig'])].$page['format'];
}
include($pg);
ctype_alpha is used to make sure the “page” passed by the user only contains characters A-Z for security (so people can’t include /etc/passwd for example).
file_exists is used to determine whether the page + extension actually exist and if they don’t, the error page is then thrown.
An idea, if you want a readable page name from $pg, you could try
$page_name = ucwords(basename($pg, $page['format']));
If you have any further questions, please do not hesitate to leave a comment,
I will update this snippet when features are suggested or questions and comments made.
20 Random Tutorials from the same category :
Advanced Navigation using Includes
RSS Feed from a MySQL Database
Building a Subscribe/Unsubscribe App in PHP with Dreamweaver CS3
Sending SMS with PHP
Dynamic PHP Google Sitemap
PHP Thumbnail Generation Script
Understanding and Validating Integers in PHP
Random Password Generation
Intro To Object: Option Variables
Hide .php extension with url rewriting using .htaccess













