标签:
function isMobile(){ if (isset ($_SERVER[‘HTTP_X_WAP_PROFILE‘])){// 如果有HTTP_X_WAP_PROFILE则一定是移动设备 return true; } if (isset ($_SERVER[‘HTTP_VIA‘])){// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息 return stristr($_SERVER[‘HTTP_VIA‘], "wap") ? true : false;// 找不到为flase,否则为true } 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; }
标签:
原文地址:http://www.cnblogs.com/xueyuwyz/p/4517577.html