zoukankan      html  css  js  c++  java
  • 判断手机浏览器还是微信浏览器(PHP)

    //判断是否 微信浏览器
    function isWeixin1() {
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
            return true;
        } else {
            return false;
        }
    }
    //判断是PC还是wap
    function isMobile1(){
        if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) return true;
        if(isset ($_SERVER['HTTP_CLIENT']) &&'PhoneClient'==$_SERVER['HTTP_CLIENT']) return true;
        if (isset ($_SERVER['HTTP_VIA'])) return stristr($_SERVER['HTTP_VIA'], 'wap') ? true : false;
        if (isset ($_SERVER['HTTP_USER_AGENT'])) {
            $clientkeywords = array(
                'nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile'
            );
            if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
                return true;
            }
        }
        if (isset ($_SERVER['HTTP_ACCEPT'])) {
            if ((strpos($_SERVER['HTTP_ACCEPT'],
                        'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'],
                        'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'],
                            'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'],
                            'text/html')))) {
                return true;
            }
        }
        return false;
    }

    手机微信浏览,两个都是true,

    电脑微信浏览是 isWeixin1=>true, isMobile1=>false,

    手机浏览器浏览都是 isWeixin1=>false, isMobile1=>true,

  • 相关阅读:
    No.2 对象与内存控制(内存分配)
    No.1 数组与内存控制
    Json解析 在VS中
    MVC 搜索防止点击其他按钮
    执行多个lanmada表达式查询
    删除重复数据
    分页
    DataSet与二进制文件和XML文件
    关于时间的转换
    转换人民币大小金额
  • 原文地址:https://www.cnblogs.com/init-007/p/11215669.html
Copyright © 2011-2022 走看看