有时候我们可能需要判断用户的终端类型,返回不同的页面效果,比如手机和电脑返回不同的url页面,那么phpcms如何判断呢?我们一起来学习一下吧!
phpcms判断是否为手机
创建一个ismobile()方法,用来判断用户是否是手机访问。
/** * function ismobile * @param $n 判断手机版 */ function ismobile(){ $useragent=isset($_server['http_user_agent']) ? $_server['http_user_agent'] : ''; $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:''; function checksubstrs($substrs,$text){ foreach($substrs as $substr) if(false!==strpos($text,$substr)){ return true; } return false; } $mobile_os_list=array('google wireless transcoder','windows ce','windowsce','symbian','android','armv6l','armv5','mobile','centos','mowser','avantgo','opera mobi','j2me/midp','smartphone','go.web','palm','ipaq'); $mobile_token_list=array('profile/midp','configuration/cldc-','160×160','176×220','240×240','240×320','320×240','up.browser','up.link','symbianos','palmos','pocketpc','sonyericsson','nokia','blackberry','vodafone','benq','novarra-vision','iris','netfront','htc_','xda_','samsung-sgh','wapaka','docomo','iphone','ipod'); $found_mobile=checksubstrs($mobile_os_list,$useragent_commentsblock) || checksubstrs($mobile_token_list,$useragent); if ($found_mobile){ return true; }else{ return false; } }
,大量的免费phpcms教程,欢迎在线学习!
以上就是phpcms判断是否为手机的详细内容。
