What are the potential pitfalls of including external files in PHP scripts, as seen in the provided code snippet?

Including external files in PHP scripts can pose security risks if the included files are not properly validated. This could potentially lead to code injection attacks or unauthorized access to sensitive information. To mitigate these risks, it is important to sanitize and validate any external files before including them in the script.

<?php
// Validate and sanitize the file path before including
$filepath = 'path/to/external/file.php';

if (file_exists($filepath)) {
    include_once($filepath);
} else {
    echo "File not found.";
}
?>