Entry
How to a make page with variables, so you could run index.php?type=file.name ; and if the file name is not specified, it will go to a specific page.
How to do something similar to : index.php?home vs. index.php?type=home
Regarding This Statement : include $type . '.php'; , lets say i want to include 2 extensions instead
Apr 3rd, 2001 09:02
Philip Olson, GamerZ Chan,
This may help :
<?php
// Includes we'll allow
$allowed = array('about','links','main','forum');
// If called upon include is allowed, include it.
if ( in_array($type,$allowed) ) {
// Using .php as our extention
include $type . '.php';
// Else use default.php as $allowed is not allowed.
} else {
include 'default.php';
}
?>
Examples :
foo.php?type=about // includes about.php
foo.php?type=/etc/passwd/ // includes default.php
foo.php // includes default.php
This will have to be expanded to find your directory paths and can use
additional error checking. Regarding the second question and this :
foo.php?about
You can replace all instances of $type with $QUERY_STRING in the above
code snippet and it'll work with foo.php?about including about.php