那些听不见音乐的人以为跳舞的人疯了。
无言博客
一个菜鸟程序员,在复制粘贴的道路上越走越远!!!
PHP判断是否移动端
无言博客 206 2020-3-4
<?php
//PHP判断是否移动端
if(is_mobile()){
    echo "我是移动端";
}else{
    echo "我是PC端";
}

function is_mobile(){
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){
        return true;
    } 
    if (isset ($_SERVER['HTTP_VIA'])){ 
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    } 
    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');
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))){
            return true;
        } 
    }
    if (isset ($_SERVER['HTTP_ACCEPT'])){
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))){
            return true;
        } 
    } 
    return false;
}
?>
END

发表评论: