How can one ensure that all pages are included in a central index.php for security purposes?

To ensure that all pages are included in a central index.php for security purposes, you can create a whitelist array of allowed pages and check if the requested page is in the whitelist before including it. This helps prevent unauthorized access to sensitive files and limits the scope of potential security vulnerabilities.

<?php
$whitelist = ['page1.php', 'page2.php', 'page3.php'];

$page = $_GET['page'] ?? 'default.php';

if (in_array($page, $whitelist)) {
    include($page);
} else {
    include('error.php');
}
?>