PHP判断是否是手机浏览器

1713次阅读  |  发布于5年以前
function is_mobile()
    {
        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'
            );
            // 从HTTP_USER_AGENT中查找手机浏览器的关键字
            if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))){
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8