建站QQ:978724145

php判断是pc还是mobile方法

在自己的站点里面引用方法

function is_mobile(){$regExp="/nokia|iphone|ipad|ipod|android|mobile|samsung|sony|htc|motorola|lg|lenovo|blackberry|meizu|oppo|ericsson|huawei|dopod|amoi|gionee|^sie\-|^bird|^zte\-|haier|blazer|netfront|helio|hosin|novarra|techfaith|palmsource|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|symbian|smartphone|midp|wap|phone|windows ce|CoolPad|webos|iemobile|^spice|longcos|pantech|portalmmm|alcatel|ktouch|nexian|^sam\-|s[cg]h|^lge|philips|sagem|wellcom|bunjalloo|maui|jig\s browser|hiptop|ucweb|ucmobile|opera\s*mobi|opera\*mini|mqqbrowser|^benq|^lct480×640|640x480|320x320|240x320|320x240|176x220|220x176/i";if(!isset($_SERVER['HTTP_USER_AGENT'])){return true;}else{return @isset($_SERVER['HTTP_X_WAP_PROFILE'])||@isset($_SERVER['HTTP_PROFILE'])||((isset($_SERVER['HTTP_VIA']))?(stristr($_SERVER['HTTP_VIA'], "wap")?true:false):false)||preg_match($regExp,strtolower($_SERVER['HTTP_USER_AGENT']));}}

$a= (is_mobile())?'mobile':'pc';

if($a=="mobile"){

echo "这是手机访问的网站,可以跳转网址了";

exit;

}else{

  echo "这是pc访问的网站,可以跳转至pc的网址";

exit;

}

力劦工作室提供

 

posted @ 2015-07-21 11:20  吴晓敏  阅读(438)  评论(0)    收藏  举报
天地游新闻网