zoukankan      html  css  js  c++  java
  • 获取用户所属浏览器和设备

    function getBrowser($agent){
    	$known = array('baidubrowser','QQBrowser','Maxthon','UC','UCBrowser','UBrowser','MetaSr', 'TheWorld','360se','360browser','115Browser','LBBrowser','2345Explorer','2345chrome','SogouMobileBrowser','TaoBrowser','baiduboxapp','MiuiBrowser'
    			,'EUI Browser','CoolNovo','Edge','Firefox','Chrome','Safari','MSIE','Opera','Netscape', 'Konqueror', 'Gecko');
    	$browser = newStripos($agent,$known,true);
    	if ($browser == 'MetaSr'){
    		$browser = 'sougouBrowser';
    	}
    	return $browser ? $browser : 'other';
    }
    

      

    function newStripos($string,$arr,$returnValue = false){
    	if (empty($string)) return false;
    	foreach ((array)$arr as $v){
    		if (stripos($string,$v) !== false){
    
    			$return = $returnValue ? $v : true;
    			return $return;
    		}
    	}
    	return false;
    }
    

      

    function getDevice($agent){
    	//Mozilla/5.0 (Linux; Android 6.0; Le X620; Build/HEXCNFN5902606111S; wv) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.92 Mobile Safari/537.36 SogouMSE,SogouMobileBrowser/5.6.8
    	$device = '';
    	if (stripos($agent,'iphone')){
    		$device = 'iphone';
    	}elseif (stripos($agent,'ipad')){
    		$device = 'ipad';
    	}elseif(stripos($agent,'android')  !== false && preg_match('/;(.*);?s+Build/iU', $agent,$match)){
    		$info = explode(';', $match[1]);
    		$device = $info[count($info)-1];
    		print_r($info);
    	}  else {
    		$known = array( 'phone', 'mobile', 'wap', 'netfront', 'java', 'opera mobi', 'opera mini',
    			'ucweb', 'windows ce', 'symbian', 'series', 'webos', 'sony', 'blackberry', 'dopod', 'nokia', 'samsung',
    			'palmsource', 'xda', 'pieplus', 'meizu', 'midp', 'cldc', 'motorola', 'foma', 'docomo', 'up.browser',
    			'up.link', 'blazer', 'helio', 'hosin', 'huawei', 'novarra', 'coolpad', 'webos', 'techfaith', 'palmsource',
    			'alcatel', 'amoi', 'ktouch', 'nexian', 'ericsson', 'philips', 'sagem', 'wellcom', 'bunjalloo', 'maui', 'smartphone',
    			'iemobile', 'spice', 'bird', 'zte-', 'longcos', 'pantech', 'gionee', 'portalmmm', 'jig browser', 'hiptop',
    			'benq', 'haier', '^lct', '320x320', '240x320', '176x220', 'windows phone');
    		$device = newStripos($agent,$known,true);
    	}
    	return $device ? $device : 'other';
    	
    }
    

      

  • 相关阅读:
    java中 Hex(十六进制)和byte[]相互转换
    byte[]和File相互转换
    Stringboot MultiPartFile 转 File
    mysql8.0+运行报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. 解决办法
    idea激活
    mysql8安装成功过后navicat连接失败
    AJAX的使用
    单文件上传和多文件上传实例
    监听器的使用
    SQL分页技术
  • 原文地址:https://www.cnblogs.com/zihai/p/7136347.html
Copyright © 2011-2022 走看看