全网整合营销服务商

营销型网站+SEO优化+关键词快排=一站式服务

免费咨询热线:15959292472

[杭州seo网站优化公司]php如何判断是手机访问网站还是电脑访问

  

 

  php判断是手机访问网站还是电脑访问网站的方法:首先打开终端编辑器;然后输入判断代码【CheckSubstrs($mobile_token_list,$useragent)】;最后输出结果即可。Python教程

  

 

  相关学习推荐:php编程(视频)】

  php判断是手机访问还是电脑访问网站的方法:

  方法1:

  

<?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; } } function checkSubstrs($list,$str){ $flag = false; for($i=0;$i<count($list);$i++){ if(strpos($str,$list[$i]) > 0){ $flag = true; break; } } return $flag; } if(check_wap()){ echo "wap"; }else{ echo "web"; } ?>

 

  方法2:

  

<?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 '手机登录'; else echo '电脑登录'; ?>

 

  想了解更多编程学习,[兰州seo公司排名]Redis RDB方式数据备份与恢复【详解】。敬请关注php培训栏目![杭州seo网站优化公司]

  

 

  以上就是php如何判断是手机访问网站还是电脑访问网站的详细内容,后端开发更多请关注久澳传媒编程栏目其它相关文章!

[杭州seo网站优化公司]php如何判断是手机访问网站还是电脑访问网站

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。