判断当前是移动端还是PC端 判断是微信浏览器还是非微信浏览器

 需求分析:

        在我现有的项目中,使用MVC模型,移动端PC端主方法都放在了C中,移动端使用

is_mobile函数来区分移动端PC端,在移动端需要区分微信浏览器非微信浏览器,所以经过研究和实验,发现了以下的方法:

区分移动端和PC端:

        $_SERVER['HTTP_USER_AGENT']  的作用:用来检查浏览页面的访问者在用什么操作系统(包括版本号)浏览器(包括版本号)和用户个人偏好的代码,所以使用了枚举来判断是移动端还是PC端

function is_mobile() {

        $user_agent = $_SERVER['HTTP_USER_AGENT'];

        $mobile_agents=Array(

        "240x320","acer","acoon","acs","abacho","ahong","airness","alcatel",

        "amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532",

        "asus","audio","aumic","avantogo","becker","benq","bilbo","bird","blackberry",

        "blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine",

        "eric","etouch","fly","fly_","fly","go.web","goodaccess","gradiente","grundig",

        "haier","hedy","hitachi","htc","huawei","hutchison","inno","ipaq","ipod",

        "jbrowser","kddi","kgt","kwc","lenovo","lg","lg2","lg3","lg4","lg5","lg7",

        "lg8","lg9","lg","lge","lge9","longcos","maemo","mercator","meridian",

         "micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-",

        "moto","nec-","netfront","newgen","nexian","nfbrowser","nintendo","nitro",

        "nokia","nook","novarra","obigo","palm","panasonic","pantech",

        "philips","phone","pg","playstation","pocket","pt","qc","qtek","rover",

        "sagem","sama","samu","sanyo","samsung","sch-",

        "scooter","sec-","sendo","sgh-","sharp","siemens",

        "sie-","softbank","sony","spice","sprint","spv",

        "symbian","talkabout","tcl-","teleca","telit","tianyu","tim-",

        "toshiba","tsm","up.browser","utec","utstar","verykool",

        "virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser",

        "wii","windows ce","wireless","xda","xde","zte"

);

        $is_mobile = false;

        foreach ($mobile_agents as $device) {

            if (stristr($user_agent, $device)) {

                $is_mobile = true;

                break;

            }

        }

        return $is_mobile;

    }

 判断是微信浏览器还是非微信浏览器:

function isWeixin() {

  if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {

            return true;

  } else {

            return false;

  }

}

你可能感兴趣的:(php,微信,edge浏览器,安全,前端)