3

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?

Insu Yun
  • 76
  • 4
  • I think you'll want to pass the `$default_browser` value directly to [`get_browser()`](http://php.net/manual/en/function.get-browser.php). Changing the `$_SERVER` value does not change the actual user-agent header and "[b]y default, the value of HTTP User-Agent header is used". But there may be more than one issue here; do you get the warning even without trying to redefine the user-agent value? This [bug report](https://bugs.php.net/bug.php?id=69983) looks relevant. – showdev Dec 11 '15 at 18:08

1 Answers1

0

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

ThaDafinser
  • 499
  • 3
  • 13