What potential pitfalls should be considered when handling language selection in PHP?

When handling language selection in PHP, potential pitfalls to consider include ensuring proper sanitization of user input to prevent injection attacks, properly validating and sanitizing language codes to avoid errors or unexpected behavior, and implementing a secure method for storing and retrieving language preferences.

// Example of sanitizing user input for language selection
$language = isset($_GET['lang']) ? filter_var($_GET['lang'], FILTER_SANITIZE_STRING) : 'en';