Hi Frndz,
I have made this code to detect Browser but i had only few browsers so for those i had done fully with version but for browsers which i dont have i have worked till detecting only so please complete it your self
Code :
<?php
function Browser_Detection() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/MSIE/i', $user_agent)) {
$agentver=explode("MSIE",$user_agent);
$agentver=explode(";",$agentver[1]);
$agentver=$agentver[0];
$ver1 = explode(" ",$agentver);
$ver1 = explode(".",$ver1[1]);
$ver = $ver1[0];
$BrowVer = "IE-".$ver;
return $BrowVer;
}
elseif (preg_match('/Firefox/i', $user_agent)) {
$agentver=explode("Firefox/",$user_agent);
$agentver=explode(" ",$agentver[1]);
$agentver=$agentver[0];
$ver1 = explode(".",$agentver);
$ver = $ver1[0];
$BrowVer = "MFF-".$ver;
return $BrowVer;
}
elseif (preg_match("/iPhone/i", $user_agent)) {
return "iPhone";
}
else if (preg_match("/Android/i", $user_agent)) {
$agentver=explode("Android ",$user_agent);
$agentver=explode(";",$agentver[1]);
$agentver=$agentver[0];
$result = "Android-".$agentver;
return $result;
}
elseif (preg_match('/Chrome/i', $user_agent)) {
$agentver=explode("Chrome/",$user_agent);
$agentver=explode(" ",$agentver[1]);
$agentver=$agentver[0];
$ver1 = explode(".",$agentver);
$ver = $ver1[0];
$BrowVer = "GCH-".$ver;
return $BrowVer;
}
elseif (preg_match('/Safari/i', $user_agent)) {
return "Apple Safari";
}
elseif (preg_match('/Opera/i', $user_agent)) {
return "Opera";
}
elseif (preg_match('/Netscape/i', $user_agent)) {
return "Netscape Navigator";
}
elseif (preg_match('/Flock/i', $user_agent)) {
return "Flock";
}
elseif (preg_match('/Lynx/i', $user_agent)) {
return "Lynx";
}
else {
return "<br>Non-Listed Browser Browser";
}
}
echo Browser_Detection();
?>
Output :
expected -
for Internet Explorer it shows IE-<version>
for Google Chrome it shows GCH-<version>
for Mozilla Firefox it shows MFF-<version>
for Android it will show Android-<version>
I have made this code to detect Browser but i had only few browsers so for those i had done fully with version but for browsers which i dont have i have worked till detecting only so please complete it your self
Code :
<?php
function Browser_Detection() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/MSIE/i', $user_agent)) {
$agentver=explode("MSIE",$user_agent);
$agentver=explode(";",$agentver[1]);
$agentver=$agentver[0];
$ver1 = explode(" ",$agentver);
$ver1 = explode(".",$ver1[1]);
$ver = $ver1[0];
$BrowVer = "IE-".$ver;
return $BrowVer;
}
elseif (preg_match('/Firefox/i', $user_agent)) {
$agentver=explode("Firefox/",$user_agent);
$agentver=explode(" ",$agentver[1]);
$agentver=$agentver[0];
$ver1 = explode(".",$agentver);
$ver = $ver1[0];
$BrowVer = "MFF-".$ver;
return $BrowVer;
}
elseif (preg_match("/iPhone/i", $user_agent)) {
return "iPhone";
}
else if (preg_match("/Android/i", $user_agent)) {
$agentver=explode("Android ",$user_agent);
$agentver=explode(";",$agentver[1]);
$agentver=$agentver[0];
$result = "Android-".$agentver;
return $result;
}
elseif (preg_match('/Chrome/i', $user_agent)) {
$agentver=explode("Chrome/",$user_agent);
$agentver=explode(" ",$agentver[1]);
$agentver=$agentver[0];
$ver1 = explode(".",$agentver);
$ver = $ver1[0];
$BrowVer = "GCH-".$ver;
return $BrowVer;
}
elseif (preg_match('/Safari/i', $user_agent)) {
return "Apple Safari";
}
elseif (preg_match('/Opera/i', $user_agent)) {
return "Opera";
}
elseif (preg_match('/Netscape/i', $user_agent)) {
return "Netscape Navigator";
}
elseif (preg_match('/Flock/i', $user_agent)) {
return "Flock";
}
elseif (preg_match('/Lynx/i', $user_agent)) {
return "Lynx";
}
else {
return "<br>Non-Listed Browser Browser";
}
}
echo Browser_Detection();
?>
Output :
expected -
for Internet Explorer it shows IE-<version>
for Google Chrome it shows GCH-<version>
for Mozilla Firefox it shows MFF-<version>
for Android it will show Android-<version>
Comments