如题。本人试过的方法有:
1).通过分辨率来判断,但发现目前有些手机分辨率也很大,其他一些手持设备(比如iPad)的分辨率也比较大。所以分辨率很多时候很难真正分辨出是来自手机或是电脑。
2).通过http head头信息中的User-Agent来分析来自手机还是电脑,但发现准确率也无法保证是100%。
请大家给点建议,不甚感激!

解决方案 »

  1.   

    ua可以伪造,ip有wifi其实服务器拿到的信息都是客户端告诉你的,凭这些信息很难确定客户端类型,就好比我告诉你说我是个亿万富翁,你根本无从判断真假。不过ua头+ip段+分辨率还是可以识别大部分的
      

  2.   

    通过User-Agent获取操作系统信息和客户端浏览器判断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;   
    } 但不能100%的判断准确。比如电脑用户可以在firefox浏览器设置User-Agent,可以模拟手机环境访问。
    但我觉得以上代码我觉可以判断99%的手机用户了。
    以下是绝大部分手机获取User-Agent的特点
    1. “iPhone” – all iPhone models contain string “iPhone” in their user agent properties.
    2. “Android” – same note as above with some exceptions.
    3. “MIDP” – many mobile devices contain string “MIDP”. Some of this devices can have screen big enough to properly display regular version of your site. So think..
    4. “Opera Mobi” – some of mobiles contain this string detecting mobile version of Opera.
    5. “Opera Mini” – some of mobiles contain this string …
    6. “BlackBerry” – one of most popular smartphones.
    7. “HP iPAQ” – Hewlett Packard smartphone?
    8. “IEMobile” – microsoft IE mobile version.
    9. “MSIEMobile” – the same as above.
    10.”Windows Phone” – microsoft mobile OS detection.
    11.”HTC” – sometimes htc phones contain nothing specific but this.
    12.”LG” – LG.
    13.”MOT” – Motorola.
    14.”Nokia” – just Nokia.
    15.”Symbian” – Symbian OS detection.
    16.”Fennec” – mobile Firefox.
    17.”Maemo” – linux version from Nokia. Is it may be used only on phones?
    18.”Tear” – some mobile browser from/for Nokia?
    19.”Midori” – it seems like Nokia gays have nothing to do. For what so many browsers?
    20.”armv6l” – some string detecting Nokia phones.
    21.”armv7l” – .. above. “armv” can be used as generic version.
    22.”Windows CE”.
    23.”WindowsCE” – variant of above.
    24.”Smartphone” – some smartphones (why not all?!) contain this string.
    25.”240×320″ – .. above. I see the future: soon (already?) web designers will take these parameters directly to their site width and height.
    26.”176×220″, “320×320″, “160×160″ – same as above.
    27.”webOS” – Palm webOS detection.
    28.”Palm” – just Palm.
    29.”Sagem” – more less known phone.
    30.”Samsung”.
    31.”SGH” – Samsung.
    32.”Siemens”, “SIE” – Siemens.
    33.”SonyEricsson”.
    34.”MMP” some phones contain this string in their user-agents.
    35.”UCWEB” – just another mobile browser.
    36. “iPad” – all iPad models contain string “iPad” in their user agent properties.
      

  3.   

    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
      

  4.   

    再 根据不同的客户端请求不同的URL
      

  5.   

    没法百分之百的。
    可以结合判断User-Agent和屏幕分辨率来判断。
      

  6.   

    貌似通过分析请求头的方法不能实现。一个人如果对HTTP协议比较熟悉的话,跟本不需要浏览器就可以访问你的服务。
    如果你的系统是BS结构的话,还可以通过自定义协议方式来做的。 看看有没有高人出来说两句。
      

  7.   

    原来这样啊,但是我看联通的网站就能够非常快的分辨出来
    我是否来着手机wap
      

  8.   

    现在好多电脑端软件可以模拟手机联网  登录手机网站  下载wap网站的资源
    能完全区分吗