php进行判断PC还是手机端代码

     之前网站判断移动还是手机跳转都是用js实现,今天给大家分享一个自己用的php判断移动或者PC

       

<?php 
function check_wap() {  
 if (isset($_SERVER['HTTP_VIA'])) return true;  
 if (isset($_SERVER['HTTP_X_NOKIA_CONNECTION_MODE'])) return true;  
 if (isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID'])) return true;  
 if (strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0) {  
  // Check whether the browser/gateway says it accepts WML.  
  $br = "WML";  
 } else {  
  $browser = isset($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : '';  
  if(empty($browser)) return true;
  $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,$browser) ||  
       checkSubstrs($mobile_token_list,$browser); 
 if($found_mobile)
  $br ="WML";
 else $br = "WWW";
 }  
 if($br == "WML") {  
  return true;  
 } else {  
  return false;  
 }  
}
?>

  

posted @ 2019-02-25 15:54  圆柱模板  阅读(362)  评论(0编辑  收藏  举报