What are the potential pitfalls of using include() to load content into a div?

One potential pitfall of using include() to load content into a div is that it can expose sensitive server-side information if not properly secured. To mitigate this risk, it is important to validate user input and sanitize any data being included. Additionally, using a whitelist approach to limit the files that can be included can help prevent unauthorized access to files on the server.

<?php
// Example of including content into a div with proper validation and sanitization
$allowed_files = ['content1.php', 'content2.php']; // Whitelist of allowed files

if(isset($_GET['page']) && in_array($_GET['page'], $allowed_files)) {
    $page = $_GET['page'];
    include($page);
} else {
    echo "Invalid page requested.";
}
?>