【发布时间】:2015-07-28 12:36:16
【问题描述】:
我编写了一个服务器端脚本来检测客户端的用户代理,然后执行以下三件事之一:
- 如果是 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) 像 iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like 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;
}
?>
【问题讨论】:
标签: android ios mobile windows-phone-8.1 user-agent