Good day everyone! This tutorial is all about Identify Your Browser and Platform Used in PHP I’m gonna show you on how to Identify Your Browser and Platform Used in PHP
PHP has some useful environment variables which can be seen in the phpinfo.php page that was used to setup the PHP environment.
HTTP_USER_AGENT is one of the environment variables set by PHP. This identifies the user’s browser and operating system.
The PHP provides function called getenv() to access the values of all the environment variables. The information contained in the HTTP_USER_AGENT environment can be used to create dynamic content appropriate to the browser.
Below are the following codes which demonstrates how you can identify a client browser and operating system:
[php]<?php<?php $viewer = getenv(“HTTP_USER_AGENT”); $browser = “An unidentified browser”; if (preg_match(“/MSIE/i”, “$viewer”)) { $browser = “Internet Explorer”; } else if (preg_match(“/Netscape/i”, “$viewer”)) { $browser = “Netscape”; } else if (preg_match(“/Mozilla/i”, “$viewer”)) { $browser = “Mozilla”; } $platform = “An identified OS”; if (preg_match(“/Windows/i”, “$viewer”)) { $platform = “Windows”; } else if (preg_match(“/Linux/i”, “$viewer”)) { $platform = “Linux”; } echo “You are using $browser on $platform.”;?>[/php]
The codes above shows the output:
You are using Mozilla on Windows.
This result may be different for your computer, depending on what browser you are using.
That’s all.
If you have questions regarding this tutorial entitled as “Identify Your Browser & Platform Used in PHP” feel free to contact us by commenting below or visit on our contact page. Thank you.
Other Articles you might read also: