We will to write a function in PHP using $_SERVER['HTTP_USER_AGENT'] to detect the browser an d SO of the client
function detect() {
$browser=array("SAFARI","CHROME","IE","EDGE","OPR","MOZILLA","NETSCAPE","FIREFOX");
# default values for browser an SO
$info['browser'] = "OTHER";
$info['os'] = "OTHER";
# search browser and SO
foreach($browser as $parent)
{
$s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent);
$f = $s + strlen($parent);
$version = substr($_SERVER['HTTP_USER_AGENT'], $f, 15);
$version = preg_replace('/[^0-9,.]/','',$version);
if ($s)
{
$info['browser'] = $parent;
$info['version'] = $version;
}
}
return $info;
}
My wish is that you find usefull this function , and can be used in your programs to detect Browser and SO and show diferent pages , depending of your needs
Top comments (1)
You should escape
.
on version check expression: