How to get user agent in PHP

Olga Budnik picture Olga Budnik · Apr 20, 2012 · Viewed 147.1k times · Source

I'm using this JS code to know what browser is user using for.

<script>
  document.write(navigator.appName);
</script>

And I want to get this navigator.appName to php code to use it like this:

if ($appName == "Internet Explorer") {
  // blabla
}

How can I do it?

Answer

noli picture noli · Apr 20, 2012

Use the native PHP $_SERVER['HTTP_USER_AGENT'] variable instead.