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

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

PHP中文网
PHP中文网원래의
2016-05-25 17:01:161009검색

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;;
?>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.