HTTP_USER_AGENT获取用户客户端信息

$agent = $_SERVER['HTTP_USER_AGENT'];
$brower = array(
      'MSIE' => 1,
      'Firefox' => 2,
      'QQBrowser' => 3,
      'QQ/' => 3,
      'UCBrowser' => 4,
      'MicroMessenger' => 9,
      'Edge' => 5,
      'Chrome' => 6,
      'Opera' => 7,
      'OPR' => 7,
      'Safari' => 8,
      'Trident/' => 1
);
$system = array(
      'Windows' => 1,
      'Macintosh'=> 2,
      'Android' => 3,
      'iPhone' => 4,
      'iPad' => 5,
      'Windows Phone' => 6
);


$browser_num = 0;//未知
$system_num = 0;//未知
foreach($brower as $bro => $val){
   if(stripos($agent, $bro) !== false){
      $browser_num = $val;
      break;
   }
}
foreach($system as $sys => $val){
   if(stripos($agent, $sys) !== false){
      $system_num = $val;
      break;
   }
}
//dump($agent);die;
//echo $browser_num;die;
return array('sys' => $system_num, 'bro' => $browser_num);




$agent 在mac设备上的显示
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36 QQBrowser/4.1.4132.400"
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8"
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:50.0) Gecko/20100101 Firefox/50.0

你可能感兴趣的:(php)