查看: 592|回复: 0

[PHP代码] PHP验证终端类型是否为手机的简单实例

发表于 2017-11-26 10:02:34

实例如下:

  1. /**
  2. * 判断当前访问的用户是 PC端 还是 手机端 返回true 为手机端 false 为PC 端
  3. * @return boolean
  4. */
  5. function isMobile(){
  6. $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
  7. //echo $useragent;die;
  8. $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';
  9. function CheckSubstrs($substrs,$text){
  10. foreach($substrs as $substr)
  11. if(false!==strpos($text,$substr)){
  12. return true;
  13. }
  14. return false;
  15. }
  16. $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');
  17. $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');
  18. $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||
  19. CheckSubstrs($mobile_token_list,$useragent);
  20. if ($found_mobile){
  21. return true;
  22. }else{
  23. return false;
  24. }
  25. }
复制代码

以上这篇PHP验证终端类型是否为手机的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持程序员之家。



回复

使用道具 举报

关闭

站长推荐上一条 /1 下一条