<?php
# Браузер пользователя
function browser($agent) {
if(empty($agent)) { $agent = $_SERVER['HTTP_USER_AGENT']; }
if (stripos($agent, 'Avant Browser') !== false) {
return 'Avant Browser';
} elseif (stripos($agent, 'Acoo Browser') !== false) {
return 'Acoo Browser';
} elseif (stripos($agent, 'MyIE2') !== false) {
return 'MyIE2';
} elseif (preg_match('|Iron/([0-9a-z\.]*)|i', $agent, $pocket)) {
return 'SRWare Iron ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|Chrome/([0-9a-z\.]*)|i', $agent, $pocket)) {
return 'Chrome ' . subtok($pocket[1], '.', 0, 3);
} elseif (preg_match('#(Maxthon|NetCaptor)( [0-9a-z\.]*)?#i', $agent, $pocket)) {
return $pocket[1] . $pocket[2];
} elseif (stripos($agent, 'Safari') !== false && preg_match('|Version/([0-9]{1,2}.[0-9]{1,2})|i', $agent, $pocket)) {
return 'Safari ' . subtok($pocket[1], '.', 0, 3);
} elseif (preg_match('#(NetFront|K-Meleon|Netscape|Galeon|Epiphany|Konqueror|Safari|Opera Mini|Opera Mobile/Opera Mobi)/([0-9a-z\.]*)#i', $agent, $pocket)) {
return $pocket[1] . ' ' . subtok($pocket[2], '.', 0, 2);
} elseif (stripos($agent, 'Opera') !== false && preg_match('|Version/([0-9]{1,2}.[0-9]{1,2})|i', $agent, $pocket)) {
return 'Opera ' . $pocket[1];
} elseif (preg_match('|Opera[/ ]([0-9a-z\.]*)|i', $agent, $pocket)) {
return 'Opera ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|Orca/([ 0-9a-z\.]*)|i', $agent, $pocket)) {
return 'Orca ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('#(SeaMonkey|Firefox|GranParadiso|Minefield|Shiretoko)/([0-9a-z\.]*)#i', $agent, $pocket)) {
return $pocket[1] . ' ' . subtok($pocket[2], '.', 0, 3);
} elseif (preg_match('|rv:([0-9a-z\.]*)|i', $agent, $pocket) && strpos($agent, 'Mozilla/') !== false) {
return 'Mozilla ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|Lynx/([0-9a-z\.]*)|i', $agent, $pocket)) {
return 'Lynx ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|MSIE ([0-9a-z\.]*)|i', $agent, $pocket)) {
return 'IE ' . subtok($pocket[1], '.', 0, 2);
} elseif (preg_match('|Googlebot/([0-9a-z\.]*)|i', $agent, $pocket)) {
return 'Google Bot ' . subtok($pocket[1], '/', 0, 2);
} elseif (preg_match('|Yandex|i', $agent)) {
return 'Yandex Bot ';
} elseif (preg_match('|Nokia([0-9a-z\.\-\_]*)|i', $agent, $pocket)) {
return 'Nokia '.$pocket[1];
} else {
$agent = preg_replace('|http://|i', '', $agent);
$agent = strtok($agent, '/ ');
$agent = substr($agent, 0, 22);
$agent = subtok($agent, '.', 0, 2);
if (!empty($agent)) {
return $agent;
}
}
return 'Unknown';
}
?>