zoukankan      html  css  js  c++  java
  • php 机型 浏览器 操作系统判断

    机型

    if(!function_exists('get_client_device')){
        function get_client_device(){
            if(request()->isMobile()){
                $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
    
                if(preg_match('/iPhones([^s|;]+)/i', $agent)) {
                    return 'iphone';
                }elseif(preg_match('/SAMSUNG|Galaxy|GT-|SCH-|SM-s([^s|;]+)/i', $agent)) {
                    return '三星';
                }elseif(preg_match('/HRY-LX1|BLA-L09|VOG-L29|Huawei|Honor|H60-|H30-s([^s|;]+)/i', $agent)) {
                    return '华为';
                }elseif(preg_match('/M2003J15SC|Redmi|MI CC|M2002J9E|Mi 10|Mi note|MI 9|Mi 8|MI 6|MI 5|MIX 2|MI MAX 2|MIX 3|MI 6|mi ones([^s|;]+)/i', $agent)) {        
                    return '小米';
                }elseif(preg_match('/cp3705A|C3701|cp3648|C106|Coolpads([^s|;]+)/i', $agent)) {        
                    return '酷派';
                }elseif(preg_match('/ZTE|Z3153|Blade A5|U202AA|Z839s([^s|;]+)/i', $agent)) {        
                    return '中兴';
                }elseif(preg_match('/OPPO|X9007|X907|X909|R831S|R827T|R821T|R811|R2017|PBEM00|PACM00s([^s|;]+)/i', $agent)) {        
                    return 'OPPO';
                }elseif(preg_match('/HTC|Desires([^s|;]+)/i', $agent)) {        
                    return 'HTC';
                }elseif(preg_match('/Nubia|NX6|NX5|NX4s([^s|;]+)/i', $agent)) {        
                    return '努比亚';
                }elseif(preg_match('/meizu|MZ|16th|16ss([^s|;]+)/i', $agent)) {        
                    return '魅族';
                }elseif(preg_match('/Gionee|GNs([^s|;]+)/i', $agent)) {        
                    return '金立';
                }elseif(preg_match('/Hisense|HLTEs([^s|;]+)/i', $agent)) {        
                    return '海信';
                }elseif(preg_match('/Lenoves([^s|;]+)/i', $agent)) {
                    return '联想';
                }elseif(preg_match('/ONEPLUSs([^s|;]+)/i', $agent)) {
                    return '一加';
                }elseif(preg_match('/vivo Y66L|vivo X9|vivo X9i|V18|V19|V20|vivos([^s|;]+)/i', $agent)) {
                    return 'vivo';
                }elseif(preg_match('/K-Touchs([^s|;]+)/i', $agent)) {
                    return '天语';
                }elseif(preg_match('/DOOVs([^s|;]+)/i', $agent)) {
                    return '朵唯';
                }elseif(preg_match('/GFIVEs([^s|;]+)/i', $agent)) {
                    return '基伍';
                }elseif(preg_match('/Nokias([^s|;]+)/i', $agent)) {
                    return '诺基亚';
                }else{
                    return '未知机型';
                }
            }else{
                return 'PC';
            }
            
        }
    }
    

    浏览器

    if(!function_exists('get_client_brownser')){
        function get_client_brownser(){
            $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
            if (strpos($agent, "msie") !== false || strpos($agent, "trident") !== false) {
                return "IE浏览器";
            }
    
            if (strpos($agent, "edge") !== false) {
                return "Edge浏览器";
            }
            if (strpos($agent, "360se") !== false) {
                return "360浏览器";
            }
            if (strpos($agent, "micromessenger") !== false) {
                return "微信浏览器";
            }
            if (strpos($agent, "mqqbrowser") !== false) {
                return "QQ浏览器";
            }
            if (strpos($agent, "firefox") !== false) {
                return "火狐浏览器";
            }
            if (strpos($agent, "chrome") !== false) {
                return "谷歌浏览器";
            }
            if (strpos($agent, "safari") !== false) {
                return "Safari浏览器";
            }
            if (strpos($agent, "opera") !== false) {
                return "Opera浏览器";
            }
            if (strpos($agent, "se") !== false&&strpos($agent, "metasr") != false) {
                return "搜狗浏览器";
            }
            if (strpos($agent, "world") !== false) {
                return "世界之窗浏览器";
            }
            if (strpos($agent, "maxthon") !== false) {
                return "遨游浏览器";
            }
            if (strpos($agent, "ucweb") !== false) {
                return "UC浏览器";
            }
    
            return '未知浏览器';
        }
    }
    

    操作系统

    if(!function_exists('get_client_os')){
        function get_client_os(){
            $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
    
            if(strpos($agent, 'windows nt') !== false) {
                $platform = 'windows';
            } elseif(strpos($agent, 'macintosh') !== false) {
                $platform = 'mac';
            } elseif(strpos($agent, 'ipod') !== false) {
                $platform = 'ipod';
            } elseif(strpos($agent, 'ipad') !== false) {
                $platform = 'ipad';
            } elseif(strpos($agent, 'iphone') !== false) {
                $platform = 'iphone';
            } elseif (strpos($agent, 'android') !== false) {
                $platform = 'android';
            } elseif(strpos($agent, 'unix') !== false) {
                $platform = 'unix';
            } elseif(strpos($agent, 'linux') !== false) {
                $platform = 'linux';
            } else {
                $platform = 'other';
            }
    
            return $platform;
        }
    }
    
  • 相关阅读:
    varnish缓存清理
    How to change default root@ email address linux / postfix / centos?
    crontab每小时运行一次
    awk 统计文件中按照某列统计某列的和(sum)
    Linux下查看压缩文件内容的 10 种方法
    python 脚本定时删除 elk索引
    python 如何让字符串的不具有转义的反斜杠具有转义功能
    Linux安装redis和部署
    redis requires Ruby version >= 2.2.2问题
    Redis持久化--Redis宕机或者出现意外删库导致数据丢失--解决方案
  • 原文地址:https://www.cnblogs.com/lina520/p/14188737.html
Copyright © 2011-2022 走看看