Are there any potential pitfalls or security concerns when dynamically loading HTML pages in PHP?

One potential pitfall when dynamically loading HTML pages in PHP is the risk of code injection or cross-site scripting attacks if user input is not properly sanitized. To mitigate this risk, always sanitize user input before using it to dynamically load HTML pages.

<?php
// Sanitize user input before dynamically loading HTML page
$page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);

// Check if the requested page exists
if (file_exists($page . '.html')) {
    include($page . '.html');
} else {
    echo 'Page not found';
}
?>