还有哪些移动浏览器用户代理伪装成 Android and/or iPhone?
Which other mobile browser user agents pretend to be Android and/or iPhone?
我编写了一个服务器端脚本来检测客户端的用户代理,然后执行以下三项操作之一:
- 如果是 iOS 设备,请将它们发送到 Apple App Store
- 如果是 Android,请将它们发送到 Google Play
- 否则,将它们发送到我们的网站
它一直运行良好,直到最近出现了 Windows Phone 8.1 用户 - IEMobile 11 浏览器具有此用户代理:
Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 630) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537
我现在已经用初始 if
条件更新了我的脚本(见下文)来处理这个 Windows Phone 8.1 IEMobile 11 浏览器,但我想知道是否有人知道在其用户中还包含 "Android" 或 "iPhone"、"iPad" 等的任何其他常见移动浏览器(非 iOS 和非 Android)代理字符串(这样我就可以相应地更新我的脚本)?
<?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;
}
?>
有 Tizen,一个基于 Linux 的手机 OS,使用
Mozilla/5.0 (Linux; Tizen 2.2; SAMSUNG SM-Z9005) AppleWebKit/537.3
(KHTML, like Gecko) Version/2.2 like Android 4.1; Mobile 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, like 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, like Gecko) Chrome/34.0.17
我还发现 this list 这可能有用,但手动完成很费力:)
我们在门户中执行完全相同的操作(如果检测到移动设备,则将用户重定向到移动页面)。
我检测到 WP 8.1 用户代理字符串存在一些问题。
对于带有 IE 的 WP,设置为通过互联网移动,我还收到 "meaningful" UAS:
Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0;
Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 930) like iPhone OS 7_0_3
Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537
据此,如果IE移动设置为"Desktop"或通过内网调用门户,我收到:
Mozilla/5.0 (Windows NT 6.2; ARM; Trident/7.0; Touch; rv:11.0;
WPDesktop; Lumia 930) like Gecko
所以.. 结果是,我们的门户网站向 iOS 显示了移动页面,而不是向 WP 显示了移动页面。
解决方法是在 查询 iPhone 之前向 UAS 查询 "Windows Phone" 。
似乎 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
注意:在returns字符串的位置(如果找到,否则为0)。
然后,如果 重定向 客户端到相关的移动页面,如果 "iOS" 或 "Android" 或 "WP" 已设置。
否则为标准浏览器加载门户。
我编写了一个服务器端脚本来检测客户端的用户代理,然后执行以下三项操作之一:
- 如果是 iOS 设备,请将它们发送到 Apple App Store
- 如果是 Android,请将它们发送到 Google Play
- 否则,将它们发送到我们的网站
它一直运行良好,直到最近出现了 Windows Phone 8.1 用户 - IEMobile 11 浏览器具有此用户代理:
Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 630) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537
我现在已经用初始 if
条件更新了我的脚本(见下文)来处理这个 Windows Phone 8.1 IEMobile 11 浏览器,但我想知道是否有人知道在其用户中还包含 "Android" 或 "iPhone"、"iPad" 等的任何其他常见移动浏览器(非 iOS 和非 Android)代理字符串(这样我就可以相应地更新我的脚本)?
<?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;
}
?>
有 Tizen,一个基于 Linux 的手机 OS,使用
Mozilla/5.0 (Linux; Tizen 2.2; SAMSUNG SM-Z9005) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.2 like Android 4.1; Mobile 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, like 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, like Gecko) Chrome/34.0.17
我还发现 this list 这可能有用,但手动完成很费力:)
我们在门户中执行完全相同的操作(如果检测到移动设备,则将用户重定向到移动页面)。
我检测到 WP 8.1 用户代理字符串存在一些问题。
对于带有 IE 的 WP,设置为通过互联网移动,我还收到 "meaningful" UAS:
Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 930) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537
据此,如果IE移动设置为"Desktop"或通过内网调用门户,我收到:
Mozilla/5.0 (Windows NT 6.2; ARM; Trident/7.0; Touch; rv:11.0; WPDesktop; Lumia 930) like Gecko
所以.. 结果是,我们的门户网站向 iOS 显示了移动页面,而不是向 WP 显示了移动页面。 解决方法是在 查询 iPhone 之前向 UAS 查询 "Windows Phone" 。 似乎 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
注意:在returns字符串的位置(如果找到,否则为0)。
然后,如果 重定向 客户端到相关的移动页面,如果 "iOS" 或 "Android" 或 "WP" 已设置。
否则为标准浏览器加载门户。