判断是手机登录还是电脑登录的几种方式

说明:都是穷举,准确率不能够保证100%,尝试使用 分辨率+ua

1、C#

 public static bool IsMobile() {

        string m = "nokia|sony|ericsson|mot|samsung|sgh|lg|sie|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile";

         string ua = HttpContext.Current.Request.UserAgent;

         if (Regex.IsMatch(ua, m, RegexOptions.IgnoreCase))

                  return true;

          else

                  return false;

}

2、Java

static final String[] MOBILE_SPECIFIC_SUBSTRING = { "iPad","iPhone","Android","MIDP","Opera Mobi", "Opera Mini","BlackBerry","HP iPAQ","IEMobile", "MSIEMobile","Windows Phone","HTC","LG", "MOT","Nokia","Symbian","Fennec", "Maemo","Tear","Midori","armv", "Windows CE","WindowsCE","Smartphone","240x320", "176x220","320x320","160x160","webOS", "Palm","Sagem","Samsung","SGH", "SIE","SonyEricsson","MMP","UCWEB"};private boolean checkMobile() { String userAgent = request.getHeader("user-agent"); for (String mobile: MOBILE_SPECIFIC_SUBSTRING){ if (userAgent.contains(mobile) || userAgent.contains(mobile.toUpperCase()) || userAgent.contains(mobile.toLowerCase())){ return true; } } return false; }

3、

((System.Web.Configuration.HttpCapabilitiesBase)Request.Browser).IsMobileDevice

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值