What could be potential pitfalls when including files in PHP for navigation purposes?

Potential pitfalls when including files for navigation purposes in PHP include the risk of including files that are not properly sanitized, leading to security vulnerabilities such as file injection attacks. To mitigate this risk, it is important to validate and sanitize user input before including files to prevent unauthorized access to sensitive files on the server.

<?php
// Validate and sanitize user input before including files for navigation
$page = isset($_GET['page']) ? $_GET['page'] : 'home';

// Whitelist allowed pages to prevent unauthorized access
$allowed_pages = ['home', 'about', 'contact'];

// Check if the requested page is allowed
if (in_array($page, $allowed_pages)) {
    include($page . '.php');
} else {
    include('404.php');
}
?>