Reputation: 158
I use a method like this instead of using a global variable:
$page = $_GET['page'];
switch ($page) {
case 'note':
include('note.php');
break;
case 'home':
include('home.php');
break;
default:
include('home.php');
break;
}
Is there a faster and more reliable way to include files?
Upvotes: 1
Views: 44
Reputation: 89
You can validate and include like following:
$pageArr = ['note', 'home'];
if (in_array($_GET['page'], $pageArr)) {
include $_GET['page'] . '.php';
} else {
include 'default_file.php';
}
Upvotes: 1