What potential issues can arise when using the include() function in PHP to include external files?

One potential issue when using the include() function in PHP to include external files is the risk of including files from untrusted sources, which can lead to security vulnerabilities like code injection or execution of malicious scripts. To mitigate this risk, it is essential to validate and sanitize user input before including external files.

// Validate and sanitize user input before including external files
$filename = 'path/to/your/file.php';
if (strpos($filename, 'allowed_directory/') === 0) {
    include $filename;
} else {
    // Handle error or show appropriate message
}