php外包、微信开发、app开发尽在蓝普!PHP技术服务商

识别电脑还是手机访问

分享一个函数,判断是电脑访问还是手机访问

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

转载请注明来源蓝普网络并以链接形式标明本文地址
本文链接: http://www.wbphp.cn/html/y09/10859.html

作者:丁, 文辉 | 日期:2016-09-20 | 分类:新闻中心 | 评论:0 条 | 浏览:7


上一篇:
下一篇:

相关文章

发表评论

*

* 以便邮件回复


给我汇款 | 合作流程 | 看看我们 | 加入我们 Copyright 2008-2016 php外包与洛阳php培训服务商. Some Rights Reserved. 豫ICP备12025288号-1