discuz获取当前访问用户是否手机用户checkmobile()

来源:互联网 发布:php 编译扩展 编辑:程序博客网 时间:2024/05/19 19:13

discuz中不错可以借鉴的内容:

function_core.php
函数function checkmobile()

获取当前访问用户是否手机用户

function checkmobile() {    global $_G;//全局变量,在discuz中使用,其他地方可忽略    $mobile = array();    static $mobilebrowser_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');    $pad_list = array('pad', 'gt-p1000');     $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);     if(dstrpos($useragent, $pad_list)) {        return false;//当前为使用PAD用户,返回false    }    if(($v = dstrpos($useragent, $mobilebrowser_list, true))) {        $_G['mobile'] = $v;        return true;//手机端访问,返回true    }    $brower = array('mozilla', 'chrome', 'safari', 'opera', 'm3gate', 'winwap', 'openwave', 'myop');    if(dstrpos($useragent, $brower)) return false;//PC浏览器访问,返回false     $_G['mobile'] = 'unknown';//未能识别,根据访问的URL强制默认是否手机端    if($_GET['mobile'] === 'yes') {        return true;    } else {        return false;    }}


原创粉丝点击