Feeling generous. 🙂 Wrote you a quick easy to use function.
<?php
// Change $allowed_pages to contain the files you want to be allowed to load
function load_page_from_url($key) {
$allowed_pages = array('home.html', 'about.html', 'contact.html');
$allowed_page_names = array();
for($i = 0; $i < count($allowed_pages); $i++) {
// Get name without extension to $split
$split = explode('.', $allowed_pages[$i]);
array_pop($split);
$split = implode('.', $split);
$allowed_page_names[$split] = $allowed_pages[$i];
}
$requested_page = $_GET[$key];
if(array_key_exists($requested_page, $allowed_page_names)
return file_get_contents($allowed_page_names[$requested_page]);
// You can change 'throw new Exception' to 'die' if you want.
throw new Exception('404: Page not found');
}
// Example usage (considering URI is x.com/index.php?page=something:
// header here
echo load_page_from_url('page');
// footer here
// Courtesy of http://serialize.us :)
Also added this to my blog.