Are there any security concerns to consider when including files with GET variables in PHP?

When including files with GET variables in PHP, there is a security concern known as "directory traversal" where malicious users can manipulate the GET variables to access sensitive files on the server. To prevent this, it is important to validate and sanitize the GET variables before including any files.

// Validate and sanitize the GET variable before including the file
if(isset($_GET['file']) && preg_match('/^[a-zA-Z0-9_]+$/', $_GET['file'])) {
    include($_GET['file'] . '.php');
} else {
    // Handle invalid or malicious input
    echo 'Invalid file requested';
}