php判断是否在手机端电脑qq、uc浏览器里通用代码

2019-02-2715:20:55后端程序开发Comments2,659 views字数 2223阅读模式
function checkmobile()
{//判断是否在移动端代码,返回true,则在移动端,返回false则不在移动端。可以根据自己的需求定制。
    $mobile array();
    $touchbrowser_list array('iphone''android''phone''mobile''wap''netfront''java''opera mobi''opera mini',
        'ucweb''windows ce''symbian''series''webos''sony''blackberry''dopod''nokia''samsung',
        'palmsource''xda''pieplus''meizu''midp''cldc''motorola''foma''docomo''up.browser',
        'up.link''blazer''helio''hosin''huawei''novarra''coolpad''webos''techfaith''palmsource',
        'alcatel''amoi''ktouch''nexian''ericsson''philips''sagem''wellcom''bunjalloo''maui''smartphone',
        'iemobile''spice''bird''zte-''longcos''pantech''gionee''portalmmm''jig browser''hiptop',
        'benq''haier''^lct''320x320''240x320''176x220');
    $mobilebrowser_list array('windows phone');
//wap浏览器中$_SERVER['HTTP_USER_AGENT']所包含的字符串数组
    $wmlbrowser_list array('cect''compal''ctl''lg''nec''tcl''alcatel''ericsson''bird''daxian''dbtel''eastcom',
        'pantech''dopod''philips''haier''konka''kejian''lenovo''benq''mot''soutec''nokia''sagem''sgh',
        'sed''capitel''panasonic''sonyericsson''sharp''amoi''panda''zte');
    $pad_list array('pad''gt-p1000');
    $useragent strtolower($_SERVER['HTTP_USER_AGENT']);
    if (dstrpos($useragent$pad_list)) {
        return false;
    }
    if (($v = dstrpos($useragent$mobilebrowser_list, true))) {
        $_G['mobile'] = $v;
        return '1';
    }
    if (($v = dstrpos($useragent$touchbrowser_list, true))) {
        $_G['mobile'] = $v;
        return '2';
    }
    if (($v = dstrpos($useragent$wmlbrowser_list))) {
        $_G['mobile'] = $v;
        return '3'//wml版
    }
    $brower array('mozilla''chrome''safari''opera''m3gate''winwap''openwave''myop');
    if (dstrpos($useragent$brower)) return false;
    $_G['mobile'] = 'unknown';
//对于未知类型的浏览器,通过$_GET['mobile']参数来决定是否是手机浏览器
    if (isset($_G['mobiletpl'][$_GET['mobile']])) {
        return true;
    else {
        return false;
    }
}
if(checkmobile()){
    define('DDTYPE','mobile');
}else{
    define('DDTYPE','pc');
}
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9736.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/9736.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定