PHP判断是设备型号

发布时间:2016-06-08 17:34:16编辑:丝画阁阅读(1057)

//判断是否是电脑登录,还是手机登录 public function isMobil()
    { $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $useragent_commentsblock = preg_match('|\(.*?\)|', $useragent, $matches) > 0 ? $matches[0] : ''; $mobile_os_list = array ( 'Google Wireless Transcoder',
            'Windows CE',
            'WindowsCE',
            'Symbian',
            'Android',
            'armv6l',
            'armv5',
            'Mobile',
            'CentOS',
            'mowser',
            'AvantGo',
            'Opera Mobi',
            'J2ME/MIDP',
            'Smartphone',
            'Go.Web',
            'Palm',
            'iPAQ' ); $mobile_token_list = array ( 'Profile/MIDP',
            'Configuration/CLDC-',
            '160×160',
            '176×220',
            '240×240',
            '240×320',
            '320×240',
            'UP.Browser',
            'UP.Link',
            'SymbianOS',
            'PalmOS',
            'PocketPC',
            'SonyEricsson',
            'Nokia',
            'BlackBerry',
            'Vodafone','BenQ',
            'Novarra-Vision',
            'Iris',
            'NetFront',
            'HTC_',
            'Xda_',
            'SAMSUNG-SGH',
            'Wapaka',
            'DoCoMo',
            'iPhone',
            'iPod' ); $found_mobile = $this->CheckSubstrs($mobile_os_list, $useragent_commentsblock) || $this->CheckSubstrs($mobile_token_list, $useragent); if ($found_mobile)
        { echo '手机登录';
        } else { echo '电脑登录';
        }
    } 使用 User-Agent 中的字符串,并结合 HTTP Header,来检测移动设备环境。 

这个设备检测的 PHP 类库最强大的地方是,它有一个非常完整的库,

可以检测出所用的设备类型(包括操作类型,以及手机品牌等都能检测)和浏览器的详细信息。

官方主页:http://mobiledetect.net/


https://github.com/serbanghita/Mobile-Detect 


//JS判断设备
varbrowser = {
  versions:function() {
    varu = navigator.userAgent, app = navigator.appVersion;
    return{    //移动终端浏览器版本信息
      trident: u.indexOf('Trident') > -1,//IE内核
      presto: u.indexOf('Presto') > -1,//opera内核
      webKit: u.indexOf('AppleWebKit') > -1,//苹果、谷歌内核
      gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
      mobile: !!u.match(/AppleWebKit.*Mobile.*/),//是否为移动终端
      ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),//ios终端
      android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,//android终端或uc浏览器
      iPhone: u.indexOf('iPhone') > -1,//是否为iPhone或者QQHD浏览器
      iPad: u.indexOf('iPad') > -1,//是否iPad
      webApp: u.indexOf('Safari') == -1//是否web应该程序,没有头部与底部
    };
  }(),
  language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
if(browser.versions.mobile) {//判断是否是移动设备打开。browser代码在下面
    varua = navigator.userAgent.toLowerCase();//获取判断用的对象
    if(ua.match(/MicroMessenger/i) =="micromessenger") {
        //在微信中打开
    }
    if(ua.match(/WeiBo/i) =="weibo") {
        //在新浪微博客户端打开
    }
    if(ua.match(/QQ/i) =="qq") {
        //在QQ空间打开
    }
    if(browser.versions.ios) {
        //是否在IOS浏览器打开
    }
    if(browser.versions.android){
        //是否在安卓浏览器打开
    }
}else{
    //否则就是PC浏览器打开
}
functionis_weixn(){
  varua = navigator.userAgent.toLowerCase();
  if(ua.match(/MicroMessenger/i)=="micromessenger") {
    returntrue;
  }else{
    returnfalse;
  }
}
PHP判断
functionis_weixin(){
  if(strpos($_SERVER['HTTP_USER_AGENT'],'MicroMessenger') !== false ) {
      returntrue;
  } 
  returnfalse;
}

关键字