PHP Snippet · Safe Include Router

A minimal example of routing to small include files while keeping things safe:

<?php
$pages = [
    'home' => 'pages/home.php',
    'about' => 'pages/about.php',
];

$page = $_GET['page'] ?? 'home';

if (!isset($pages[$page])) {
    $page = 'home';
}

include $pages[$page];

This is the same pattern used on this site: a whitelisted map of allowed pages, no direct access to arbitrary paths.