php判断手机浏览还是web浏览,并执行相应的动作

正好需要,在网上找了好久,记录一下

 1 function isMobile(){
 2     $useragent=isset($_SERVER[‘HTTP_USER_AGENT‘]) ? $_SERVER[‘HTTP_USER_AGENT‘] : ‘‘;
 3     $useragent_commentsblock=preg_match(‘|\(.*?\)|‘,$useragent,$matches)>0?$matches[0]:‘‘;
 4     function CheckSubstrs($substrs,$text){
 5         foreach($substrs as $substr)
 6             if(false!==strpos($text,$substr)){
 7                 return true;
 8             }
 9             return false;
10     }
11     $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‘);
12     $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‘);
13
14     $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||
15               CheckSubstrs($mobile_token_list,$useragent);
16
17     if ($found_mobile){
18         return true;
19     }else{
20         return false;
21     }
22 }
23 if (isMobile()){
24     header(‘location: ./app/index.php‘);//如果为手机端,执行跳转
25 }
26 else{
27     header(‘location: ./web/index.php‘);//如果非手机端,执行跳转
28 }

时间: 2024-08-15 17:28:32

php判断手机浏览还是web浏览,并执行相应的动作的相关文章

手机,平板当中浏览和编辑DWG的CAD控件出来啦!支持ARX二次开发

控件2014.06.30 安卓开发最新更新 发布时间:2014-06-30 22:22:42 开发包下载地址:http://www.mxdraw.com/MxDraw6.0Android(20140630)TryVersion.exe 安卓手机上的apk安装包: http://www.mxdraw.com/MxDrawApp60.apk 安卓快速入门文档: http://www.mxdraw.com/AndroidDev.doc 1. 优化dwg显示速度,现在可以极速显示dwg,比市面上的任何软

php判断手机段登录,以及phpcms手机PC双模板调用

首先一段php代码判断是否为手机浏览: function isMobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) { return true; } // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息 if (isset ($_SERVER['HTTP_VIA'])) { // 找不到为flase,否则为true return stristr($_SERV

javascript判断手机浏览器版本信息

<script type="text/javascript"> /* * 智能机浏览器版本信息: * */ var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto

判断手机浏览器终端设备

判断手机浏览器终端设备 var browser = { versions: function () { var u = navigator.userAgent, app = navigator.appVersion; return { trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.indexOf('AppleWebKit') > -1, //

通过userAgent判断手机浏览器类型

我们可以通过userAgent来判断,比如检测某些关键字,例如:AppleWebKit*****Mobile或AppleWebKit,需要注意的是有些浏览器的userAgent中并不包含AppleWebKit关键字,可能会是Linux,UCBrowser等等. 1.Javascript 2. PHP 3. .NET (C#) 下面是Javascript代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

判断手机横竖屏

//判断手机横竖屏状态:window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() { if (window.orientation === 180 || window.orientation === 0) { //竖屏 } if (window.orientation === 90 || window.o

JS判断是否是微信页面,判断手机操作系统(ios或android)并跳转到不同下载页面

JS判断客户端是否是iOS或者Android 参考:http://caibaojian.com/browser-ios-or-android.html 1 function is_weixin() { 2 var ua = window.navigator.userAgent.toLowerCase(); 3 if (ua.match(/MicroMessenger/i) == 'micromessenger') { 4 return true; 5 } else { 6 return fals

MFC中浏览文件和浏览目录的实现[转]

1. 浏览文件 1 void CDlgCompare::OnBnClickedBtnSel() 2 { 3 // TODO: Add your control notification handler code here 4 UpdateData(TRUE); 5 CFileDialog fileDlg(TRUE); 6 fileDlg.m_ofn.lpstrTitle="文件打开对话框"; 7 fileDlg.m_ofn.lpstrFilter="All Files(*.*

js判断手机浏览器操作系统和微信浏览器的方法

做手机端的前端开发,少不了对手机平台的判断.如,对于app下载,就要判断在Android平台下就显示Android下载提示:在iOS平台下就显示iOS下载提示. 今天就为大家介绍一下用js判断手机客户端平台及系统平台的方法: <script type="text/javascript"> //手机端判断各个平台浏览器及操作系统平台 function checkPlatform(){ if(/android/i.test(navigator.userAgent)){ docu