Home > Backend Development > PHP Tutorial > PHP identifies whether the website is accessed from a computer or a mobile phone_PHP tutorial

PHP identifies whether the website is accessed from a computer or a mobile phone_PHP tutorial

WBOY
Release: 2016-07-13 17:17:33
Original
780 people have browsed it

Recently, a customer asked the website to determine whether it is accessed by mobile phone or computer, and then display different information, so I looked for it online. This is not original, but the emphasis is on sharing.

PHP identifies whether the website is accessed from a computer or a mobile phone_PHP tutorial

<?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&times;160&#39;,&#39;176&times;220&#39;,&#39;240&times;240&#39;,&#39;240&times;320&#39;,&#39;320&times;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;手机登录m.php100.com&#39;;
else
	echo &#39;电脑登录www.bkjia.com&#39;;
?>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/625801.htmlTechArticleRecently, customers require the website to determine whether it is accessed by mobile phone or computer, and then display different information, so on the Internet Found it, this is not original, the focus is on sharing. ?phpfunction...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template