Write a PHP script to detect the type of browser used to display the script. The
information about the browser being used can be found in the value of a special
reserved PHP variable (more accurately an array element)
$_SERVER['HTTP_USER_AGENT'] . You need to use a built-in PHP string
function to check for three keywords in $_SERVER['HTTP_USER_AGENT']:
„MSIE‟, „Firefox‟ and „Chrome‟. If „MSIE‟ is found, output “you are using Microsoft
Internet Explorer”; If „Firefox‟ is found, output “you are using Mozilla Firefox”; If
„Chrome‟ is found, output “you are using Google Chrome”; If none of the three is
found, output “you are using a browser other than Microsoft Internet Explorer,
Mozilla Firefox and Google Chrome”. See
http://www.useragentstring.com/pages...gentstring.php for a list of User Agent
Strings for different browsers.
---------
Use strpos() instead of preg matches.
<?php
/*$hay is user agent of the request and if strpo returned true, print the text.
*/
$hay = $_SERVER['HTTP_USER_AGENT'];
if strpos('MSIE', $hay) {
print "You are using IE";
}
elseif strpos('Firefox', $hay) {
print "firefox";
}
elseif strpos('Opera'. $hay) {
print "opera";
}
...
?>