So, taking a url query string such as this: ?action=home
PHP Code:
//spoof a GET request for now:
$_GET['action'] = 'home';
// create a white list
$permitted = array('home', 'about', 'error');
// set some defaults:
$variables['title'] = 'default title';
$variables['content'] = 'default content';
$variables['id'] = 'default id';
if( in_array($_GET['action'], $permitted) ){
// set up some vars if they are in your white list $permitted
$variables['title'] = $_GET['action'];
$variables['content'] = $_GET['action'] . '.php';
$variables['id'] = $_GET['action'];
}
var_dump( $variables );
I mean your example is simplistic, so the solution is also simplistic.
In the real world are you not more likely to be dealing with output which is more akin to:
PHP Code:
$variables['title'] = "Welcome to the home page";
$variables['content'] = 'home.php';
$variables['id'] = 23;
Bookmarks