码迷,mamicode.com
首页 > 其他好文 > 详细

判断浏览器类型

时间:2015-05-30 10:37:33      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

/**
     *  判断是否是手机访问
     */    
    protected function isMobile() {
        if(isset($_REQUEST[‘from_m‘])) return false;
        $userAgent = $_SERVER[‘HTTP_USER_AGENT‘];
        $os = array();
//        $os[‘webkit‘] = preg_match(‘/WebKit\/([\d.]+)/‘, $userAgent) ? true : false;
        $os[‘android‘] = preg_match(‘/(Android)\s+([\d.]+)/) || userAgent.match(/Silk-Accelerated/‘, $userAgent) ? true : false;
//        $os[‘androidICS‘] = $os[‘android‘] && preg_match(‘/(Android)\s4/‘, $userAgent) ? true : false;
//        $os[‘ipad‘] = preg_match(‘/(iPad).*OS\s([\d_]+)/‘, $userAgent) ? true : false;
        $os[‘ipod‘] = preg_match(‘/(iPod).*OS\s([\d_]+)/‘, $userAgent) ? true : false;
        $os[‘iphone‘] = !$os[‘ipad‘] && preg_match(‘/(iPhone\sOS)\s([\d_]+)/‘, $userAgent) ? true : false;
//        $os[‘webos‘] = preg_match(‘/(webOS|hpwOS)[\s\/]([\d.]+)/‘, $userAgent) ? true : false;
//        $os[‘touchpad‘] = $os[‘webos‘] && preg_match(‘/TouchPad/‘, $userAgent) ? true : false;
//        $os[‘ios‘] = $os[‘ipad‘] || $os[‘iphone‘];
//        $os[‘ios6‘] = $os[‘ios‘] &&  preg_match(‘/(OS)\s([6])/‘, $userAgent) ? true : false;
//        $os[‘playbook‘] = preg_match(‘/PlayBook/‘, $userAgent) ? true : false;
//        $os[‘blackberry‘] = $os[‘playbook‘] || preg_match(‘/BlackBerry/‘, $userAgent) ? true : false;
//        $os[‘blackberry10‘] = $os[‘blackberry‘] && preg_match(‘/Safari\/536/‘, $userAgent) ? true : false;
//        $os[‘chrome‘] = preg_match(‘/Chrome/‘, $userAgent) ? true : false;
//        $os[‘opera‘] = preg_match(‘/Opera Mobi/‘, $userAgent) ? true : false;
//        $os[‘fennec‘] = preg_match(‘/fennec/i‘, $userAgent) ? true : false;
//        $os[‘desktop‘] = !($os[‘ios‘] || $os[‘android‘] || $os[‘blackberry‘] || $os[‘opera‘] || $os[‘fennec‘] || $os[‘supportsTouch‘]);
        
        if($os[‘ipod‘] || $os[‘iphone‘] || $os[‘android‘]){
            return true;
        } else {
            return false;
        }
    }

 

判断浏览器类型

标签:

原文地址:http://www.cnblogs.com/bandbandme/p/4539831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!