Django
Django

Reputation: 158

Is there a more reliable and simple way to include php file

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

Answers (1)

ShriHans
ShriHans

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

Related Questions