我是靠谱客的博主 笑点低芒果,最近开发中收集的这篇文章主要介绍判断当前是移动端还是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;

  }

}

最后

以上就是笑点低芒果为你收集整理的判断当前是移动端还是PC端 判断是微信浏览器还是非微信浏览器的全部内容,希望文章能够帮你解决判断当前是移动端还是PC端 判断是微信浏览器还是非微信浏览器所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部