Undefined array key “HTTP_USER_AGENT”
-
Since upgrading to PHP8, my logs are full of warnings like:
Undefined array key "HTTP_USER_AGENT" in /wp-content/themes/himalayas/inc/functions.php on line 62
This is because your code doesn’t check for the existence of the key before accessing it:
$himalayas_user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
Please add ‘isset’ check for this key before trying to access it, like so:
$himalayas_user_agent = ( isset($_SERVER['HTTP_USER_AGENT']) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Undefined array key “HTTP_USER_AGENT”’ is closed to new replies.