What potential issues can arise when including files with GET variables in PHP?

When including files with GET variables in PHP, a potential issue is the risk of code injection or security vulnerabilities if the GET variables are not properly sanitized. To solve this issue, always validate and sanitize any user input, including GET variables, before using them in file includes to prevent malicious code execution.

// Validate and sanitize the GET variable before including the file
$filename = filter_var($_GET['file'], FILTER_SANITIZE_STRING);

// Check if the file exists before including it
if (file_exists($filename)) {
    include $filename;
} else {
    echo "File not found.";
}