php判断是手机访问还是电脑访问网站的方法:首先打开终端编辑器;然后输入判断登入形式代码,代码为【CheckSubstrs($mobile_token_list,$useragent)】;最后输出结果即可。
创新互联建站是一家集网站建设,青山企业网站建设,青山品牌网站建设,网站定制,青山网站建设报价,网络营销,网络优化,青山网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
【相关学习推荐: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 '电脑登录'; ?>
想了解更多编程学习,敬请关注php培训栏目!
网站栏目:php如何判断是手机访问还是电脑访问网站
文章路径:https://www.cdcxhl.com/article48/cjiphp.html
成都网站建设公司_创新互联,为您提供微信公众号、全网营销推广、虚拟主机、微信小程序、外贸建站、外贸网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联