资源描述:
《PHP判断客户端是PCweb端还是移动手机端方法.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、方法一,摘自discuz/****根据php的$_SERVER['HTTP_USER_AGENT']中各种浏览器访问时所包含各个浏览器特定的字符串来判断是属于PC还是移动端*@authordiscuz3x*@lastmodify2014-04-09*@returnBOOL*/functioncheckmobile(){global$_G;$mobile=array();//各个触控浏览器中$_SERVER['HTTP_USER_AGENT']所包含的字符串数组static$touchbrowse
2、r_list=array('iphone','android','phone','mobile','wap','netfront','java','operamobi','operamini','ucweb','windowsce','symbian','series','webos','sony','blackberry','dopod','nokia','samsung','palmsource','xda','pieplus','meizu','midp','cldc','motorola
3、','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','spic
4、e','bird','zte-','longcos','pantech','gionee','portalmmm','jigbrowser','hiptop','benq','haier','^lct','320x320','240x320','176x220');//window手机浏览器数组【猜的】static$mobilebrowser_list=array('windowsphone');//wap浏览器中$_SERVER['HTTP_USER_AGENT']所包含的字符串数组stati
5、c$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
6、','sonyericsson','sharp','amoi','panda','zte');$pad_list=array('pad','gt-p1000');$useragent=strtolower($_SERVER['HTTP_USER_AGENT']);if(dstrpos($useragent,$pad_list)){returnfalse;}if(($v=dstrpos($useragent,$mobilebrowser_list,true))){$_G['mobile']=$v;
7、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'
8、,'myop');if(dstrpos($useragent,$brower))returnfalse;$_G['mobile']='unknown';//对于未知类型的浏览器,通过$_GET['mobile']参数来决定是否是手机浏览器if(isset($_G['mobiletpl'][$_GET['mobile']])){returntrue;}else{returnfalse;}}/***判断$arr中元素字符串是否有出现在$string中*@param$string$_SERVER['H