What are the potential pitfalls of using PHP include statements to include content from one file into another?

One potential pitfall of using PHP include statements is the risk of including sensitive information or malicious code from external files. To mitigate this risk, it is important to validate and sanitize the included file path before using it in the include statement. This can help prevent unauthorized access or execution of harmful code.

// Validate and sanitize the included file path
$included_file = 'path/to/your/file.php';

if (strpos($included_file, 'allowed_directory/') === 0) {
    include $included_file;
} else {
    // Handle invalid file path
    echo 'Invalid file path';
}