Home  >  Article  >  Backend Development  >  PHP method to determine whether it is a mobile client

PHP method to determine whether it is a mobile client

一个新手
一个新手Original
2017-09-12 10:34:453850browse


<?function check_wap(){
    if(stristr($_SERVER[&#39;HTTP_VIA&#39;],"wap")){// 先检查是否为wap代理,准确度高
        return true;
    }elseif(strpos(strtoupper($_SERVER[&#39;HTTP_ACCEPT&#39;]),"VND.WAP.WML") > 0){// 检查浏览器是否接受 WML.
        return true;
   }elseif(preg_match(&#39;/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i&#39;, $_SERVER[&#39;HTTP_USER_AGENT&#39;])){//检查USER_AGENT
        return true;             
    }else{
        return false;    
   }
}
if(check_wap() && !$_GET[&#39;m&#39;]){
    Header(&#39;Location:http://www.sdceo.com/?m=wap&#39;);
}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>php判断是否手机客户端</title></head><body></body></html>

 

The above is the detailed content of PHP method to determine whether it is a mobile client. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn