What are the potential pitfalls of using $_SERVER['HTTP_USER_AGENT'] to detect client language in PHP?

Using $_SERVER['HTTP_USER_AGENT'] to detect client language in PHP can be unreliable as it relies on the browser to send the correct information. It's better to use the Accept-Language header which is specifically designed for this purpose. This header provides a list of preferred languages that the client can understand.

$language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : 'en';