What are the potential security risks associated with using the GET method to include PHP files based on user input?

Using the GET method to include PHP files based on user input can lead to security risks such as remote code execution and directory traversal attacks. To mitigate these risks, it is important to validate and sanitize user input before including any files.

// Validate and sanitize user input before including files
$user_input = $_GET['file'];
$allowed_files = ['file1.php', 'file2.php', 'file3.php'];

if (in_array($user_input, $allowed_files)) {
    include($user_input);
} else {
    echo "Invalid file requested";
}