Home >php教程 >PHP源码 >识别电脑还是手机访问网站

识别电脑还是手机访问网站

PHP中文网
PHP中文网Original
2016-05-25 17:01:161005browse

php代码

<?php
function isMobile(){  
	$useragent=isset($_SERVER[&#39;HTTP_USER_AGENT&#39;]) ? $_SERVER[&#39;HTTP_USER_AGENT&#39;] : &#39;&#39;;  
	$useragent_commentsblock=preg_match(&#39;|\(.*?\)|&#39;,$useragent,$matches)>0?$matches[0]:&#39;&#39;;  	  
	function CheckSubstrs($substrs,$text){  
		foreach($substrs as $substr)  
			if(false!==strpos($text,$substr)){  
				return true;  
			}  
			return false;  
	}
	$mobile_os_list=array(&#39;Google Wireless Transcoder&#39;,&#39;Windows CE&#39;,&#39;WindowsCE&#39;,&#39;Symbian&#39;,&#39;Android&#39;,&#39;armv6l&#39;,&#39;armv5&#39;,&#39;Mobile&#39;,&#39;CentOS&#39;,&#39;mowser&#39;,&#39;AvantGo&#39;,&#39;Opera Mobi&#39;,&#39;J2ME/MIDP&#39;,&#39;Smartphone&#39;,&#39;Go.Web&#39;,&#39;Palm&#39;,&#39;iPAQ&#39;);
	$mobile_token_list=array(&#39;Profile/MIDP&#39;,&#39;Configuration/CLDC-&#39;,&#39;160×160&#39;,&#39;176×220&#39;,&#39;240×240&#39;,&#39;240×320&#39;,&#39;320×240&#39;,&#39;UP.Browser&#39;,&#39;UP.Link&#39;,&#39;SymbianOS&#39;,&#39;PalmOS&#39;,&#39;PocketPC&#39;,&#39;SonyEricsson&#39;,&#39;Nokia&#39;,&#39;BlackBerry&#39;,&#39;Vodafone&#39;,&#39;BenQ&#39;,&#39;Novarra-Vision&#39;,&#39;Iris&#39;,&#39;NetFront&#39;,&#39;HTC_&#39;,&#39;Xda_&#39;,&#39;SAMSUNG-SGH&#39;,&#39;Wapaka&#39;,&#39;DoCoMo&#39;,&#39;iPhone&#39;,&#39;iPod&#39;);  
		  
	$found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||  
			  CheckSubstrs($mobile_token_list,$useragent);  
		  
	if ($found_mobile){  
		return true;  
	}else{  
		return false;  
	}  
}
if (isMobile())
	echo &#39;手机登录www.cuangs.com&#39;;
else
	echo &#39;电脑登录www.ydutv.com&#39;;
?>
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