<?php include 'header.php' ?>
<p>Some content goes here.</p>
<?php include 'footer.php' ?>
<?php
echo includeContent($_GET['x']);
function includeContent($x) {
// Default page if $x doesn't exist or
// isn't specified
$default = 'index';
// File extension of the file to include
// i.e. given $x=info we want to include
// info.php
$extension = '.php';
// Only allow alphanumeric characters
$x = preg_replace('/[^a-z0-9]/i', '', $x);
// If $x isn't set then or $x doesn't exist
// use the default page
if ( !isset($x) || !file_exists($x.$extension) )
$x = $default;
// Just incase $default doesn't exist
if (file_exists($x.$extension))
include($x.$extension);
}
?>
I don't see why you'd want to use that approach in the first place though. It just introduces unnecessary code and makes the URL look messy.
unless i'm reading it completely wrong isn't this one of the better ways to do it? like wordpress does.
Any good? Call with page.php?x=file_to_include (without extension)
PHP:<?php echo includeContent($_GET['x']); function includeContent($x) { // Default page if $x doesn't exist or // isn't specified $default = 'index'; // File extension of the file to include // i.e. given $x=info we want to include // info.php $extension = '.php'; // Only allow alphanumeric characters $x = preg_replace('/[^a-z0-9]/i', '', $x); // If $x isn't set then or $x doesn't exist // use the default page if ( !isset($x) || !file_exists($x.$extension) ) $x = $default; // Just incase $default doesn't exist if (file_exists($x.$extension)) include($x.$extension); } ?>
Inq, i find this the easiest way, i been out of the coding area for a very long time & just wanted to get my site done the easiest way possible,
Ok, but I don't understand what's easier about it; you don't have to do this at all!
The "index.php?page=abc" URI scheme is unnecessary in most cases. The only cases in which it makes sense are those in which you're not actually serving files but are generating content through some other mechanism (e.g. Wordpress, MVC frameworks, etc.)