zoukankan      html  css  js  c++  java
  • 判断浏览器类型

    /**
         *  判断是否是手机访问
         */    
        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).*OSs([d_]+)/', $userAgent) ? true : false;
            $os['ipod'] = preg_match('/(iPod).*OSs([d_]+)/', $userAgent) ? true : false;
            $os['iphone'] = !$os['ipad'] && preg_match('/(iPhonesOS)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;
            }
        }
  • 相关阅读:
    网络基础之物理层和数据链路层
    mysql5.6 主从不同步 存储过程大事务导致
    1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
    973. K Closest Points to Origin
    525. Contiguous Array
    1035. Uncrossed Lines
    1008. Construct Binary Search Tree from Preorder Traversal
    986. Interval List Intersections
    451. Sort Characters By Frequency
    如何在PHP中判断当前请求的类型【转】
  • 原文地址:https://www.cnblogs.com/bandbandme/p/4539831.html
Copyright © 2011-2022 走看看