function getBrowser($agent) {
$browser = array(
"MSIE 5.0" => "/msie 5.0[0-9]*/",
"MSIE 5.5" => "/msie 5.5[0-9]*/",
"MSIE 6.0" => "/msie 6.0[0-9]*/",
"MSIE 7.0" => "/msie 7.0[0-9]*/",
"MSIE 8.0" => "/msie 8.0[0-9]*/",
"MSIE 9.0" => "/msie 9.0[0-9]*/",
"Chrome" => "/chrome\/*/",
"FireFox" => "/firefox\/*/",
"Netscape" => "/x11/",
"Opera" => "/opera*/",
"Safari" => "/safari\/*/",
"Android" => "/android/",
"Mobile Safari" => "/mobile\/[0-9a-z]* safari/",
"Robot" => "/yahoo/",
"Robot" => "/bot/"
);
$agent = strtolower($agent);
foreach($browser as $name=>$exp){
if(preg_match($exp, $agent)){
$browser = $name;
}
}
return $browser;
} $u_agent = $_SERVER['HTTP_USER_AGENT'];
$browser = getBrowser($u_agent);
if($browser == 'Android' || $browser == 'Mobile Safari'){
if($browser == 'Android'){
ECHO "ANDROID";
}else{
ECHO "IPHONE";
}
}else{
ECHO "OTHER";
}
$browser = array(
"MSIE 5.0" => "/msie 5.0[0-9]*/",
"MSIE 5.5" => "/msie 5.5[0-9]*/",
"MSIE 6.0" => "/msie 6.0[0-9]*/",
"MSIE 7.0" => "/msie 7.0[0-9]*/",
"MSIE 8.0" => "/msie 8.0[0-9]*/",
"MSIE 9.0" => "/msie 9.0[0-9]*/",
"Chrome" => "/chrome\/*/",
"FireFox" => "/firefox\/*/",
"Netscape" => "/x11/",
"Opera" => "/opera*/",
"Safari" => "/safari\/*/",
"Android" => "/android/",
"Mobile Safari" => "/mobile\/[0-9a-z]* safari/",
"Robot" => "/yahoo/",
"Robot" => "/bot/"
);
$agent = strtolower($agent);
foreach($browser as $name=>$exp){
if(preg_match($exp, $agent)){
$browser = $name;
}
}
return $browser;
} $u_agent = $_SERVER['HTTP_USER_AGENT'];
$browser = getBrowser($u_agent);
if($browser == 'Android' || $browser == 'Mobile Safari'){
if($browser == 'Android'){
ECHO "ANDROID";
}else{
ECHO "IPHONE";
}
}else{
ECHO "OTHER";
}