Set $_SERVER['HTTP_USER_AGENT'] for get_browser()

2.6k Views Asked by At

I want to set $_SERVER['HTTP_USER_AGENT'] manually before calling get_browser() function.

<?php
   ...
   $_SERVER['HTTP_USER_AGENT'] = $default_browser;

   $browser = get_browser(null, true);
   print_r($browser);
?>

but it gives me an error.

PHP Warning:  get_browser(): HTTP_USER_AGENT variable is not set, cannot determine user agent name in /home/insu/a.php on line 6

Is it possible to set HTTP_USER_AGENT manually?

1

There are 1 best solutions below

0
ThaDafinser On

You can do this: php $browser = get_browser($default_browser, true); print_r($browser);

But you should not rely on get_browser() since it's really slow.

You can choose between a lot of Parsers here https://github.com/ThaDafinser/UserAgentParser