[php] How to get user agent in PHP

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?

This question is related to php user-agent

The answer is


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


You can use the jQuery ajax method link if you want to pass data from client to server. In this case you can use $_SERVER['HTTP_USER_AGENT'] variable to found browser user agent.


You could also use the php native funcion get_browser()

IMPORTANT NOTE: You should have a browscap.ini file.