首页 文章

哪些其他移动浏览器用户代理假装是Android和/或iPhone?

提问于
浏览
1

我编写了一个服务器端脚本来检测客户端的用户代理,然后执行以下三种操作之一:

  • 如果是iOS设备,请将它们发送到Apple App Store

  • 如果是Android版,请将其发送至Google Play

  • 否则,请将它们发送到我们的网站

直到最近,当一个Windows Phone 8.1用户出现时它工作正常--IEMobile 11浏览器有这个用户代理:

Mozilla / 5.0(移动; Windows Phone 8.1; Android 4.0; ARM; Trident / 7.0; Touch; rv:11.0; IEMobile / 11.0;诺基亚; Lumia 630),如iPhone OS 7_0_3 Mac OS X AppleWebKit / 537(KHTML,如Gecko )Mobile Safari / 537

我现在用最初的 if 条件更新我的脚本(见下文)来处理这个Windows Phone 8.1 IEMobile 11浏览器,但我想知道是否有人知道任何其他常见的移动浏览器(非iOS和非Android)在他们的用户代理字符串中还包括"Android"或"iPhone","iPad"等(所以我可以相应地更新我的脚本)?

<?php
$web_page_url = "http://example.com/";
$google_play_url = "http://play.google.com/store/apps/details?id=com.example.myapp";
$app_store_url = "https://itunes.apple.com/gb/app/my-app/id1234567890?mt=8";

/*
 * Detect the requesting user-agent.
 * If it's Windows Phone, send them to our website.
 * If it's Android, send them to Google Play.
 * If it's iOS, send them to Apple App Store.
 * Otherwise, send them to our website.
 */
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if (stripos($ua, 'windows phone') !== false) {

    /*
     * It's a Windows Phone (the user agent of which may also include "Android" and "iPhone")
     */
    header("Location: $web_page_url");
    exit;

}
else if (stripos($ua, 'android') !== false) {

    /*
     * It's an Android device, send them to Google Play
     */
    header("Location: $google_play_url");
    exit;

}
else if (stripos($ua, 'iphone') !== false || stripos($ua, 'ipod') !== false || stripos($ua, 'ipad') !== false) {

    /*
     * It's an iOS device, send them to Apple App Store
     */
    header("Location: $app_store_url");
    exit;

}
else {

    /*
     * It's not an Android or iPhone, so send them to the web page
     */
    header("Location: $web_page_url");
    exit;
}
?>

2 回答

  • 0

    Tizen,一个基于Linux的移动操作系统,使用

    Mozilla / 5.0(Linux; Tizen 2.2; SAMSUNG SM-Z9005)AppleWebKit / 537.3(KHTML,像Gecko)版本/ 2.2喜欢Android 4.1;移动Safari / 537.3

    新兴的Firefox OS似乎也是这样做的

    Mozilla / 5.0(Linux; U; Android 4.4 Andro-id Build / KRT16S; X11; FxOS armv7I rv:29.0)MyWebkit / 537.51.1(KHTML,与Gecko一样)Gecko / 29.0 Firefox / 29.0 Mozilla / 5.0(Macintosh; U ; Intel Mac OS X 10_9_1; en-ID)MyWebKit / 537.51.1(KHTML,与Gecko一样)Chrome / 34.0.17

    我也找到了this list,这可能是有用的,但是手动完成是很麻烦的:)

  • 2

    我们在门户网站中执行完全相同的操作(如果检测到移动设备,则将用户重定向到移动设备页面) .
    我已经检测到 WP 8.1 用户代理字符串的一些问题 . 对于使用IE的WP, set to mobile over the Internet ,我还收到"meaningful" UAS:

    Mozilla / 5.0(移动; Windows Phone 8.1; Android 4.0; ARM; Trident / 7.0; Touch; rv:11.0; IEMobile / 11.0;诺基亚; Lumia 930),如iPhone OS 7_0_3 Mac OS X AppleWebKit / 537(KHTML,如Gecko) )Mobile Safari / 537

    Whereby ,如果IE mobile设置为"Desktop"或通过Intranet调用门户,我会收到:

    Mozilla / 5.0(Windows NT 6.2; ARM; Trident / 7.0; Touch; rv:11.0; WPDesktop; Lumia 930),如Gecko

    所以......效果是,我们的门户网站已经向iOS显示了移动页面,而不是移动页面到WP . 解决方法是查询UAS以查找iPhone的查询.172903_ before . 似乎MS试图以这种方式被检测为移动设备(如果一个页面只查询iOS和Android设备),那就不好了 .

    所以我的(实际)代码(VB.net)到If:

    If AT("Windows Phone", cProtUserAgent) > 0 Then
        cMobilePlattform = "WP"
     ElseIf AT("WPDesktop", cProtUserAgent) > 0 Then
        cMobilePlattform = "WP"
     ElseIf AT("IEMobile", cProtUserAgent) > 0 Then
        cMobilePlattform = "WP"
     ElseIf AT("ZuneWP7", cProtUserAgent) > 0 Then
        cMobilePlattform = "WP"
     ElseIf AT("iPhone", cProtUserAgent) > 0 Then
        cMobilePlattform = "iOS"
     ElseIf AT("iPad", cProtUserAgent) > 0 Then 
        cMobilePlattform = "iOS"
     ElseIf AT("Android", cProtUserAgent) > 0 Then ' Android:
         cMobilePlattform = "Android" 
     End If
    

    注意:返回字符串的位置od(如果找到,否则为0) .
    然后,如果设置了"iOS"或"Android"或"WP",则将第二个if发生并且 redirects 客户端到相关的移动页面 .
    否则,门户网站将加载标准浏览器 .

相关问题