我已经写了检测客户端的用户代理服务器端脚本,然后做的三两件事之一:哪些其他移动浏览器用户代理假装为Android和/或iPhone?
- 如果是iOS设备,并将它们发送到苹果App Store
- 如果它是一个机器人,并将它们发送到谷歌播放
- 否则,将其发送到我们的网站
这是工作正常,直到最近,当了Windows Phone 8.1的用户来了 - 对此,有这个用户代理IEMobile 11浏览器:
Mozilla/5.0(Mobile; Windows Phone 8.1; Android 4.0;臂;三叉戟/ 7.0;触摸; RV:11.0; IEMobile/11.0;诺基亚;的Lumia 630),如iPhone OS 7_0_3的Mac OS X为AppleWebKit/537(KHTML,例如Gecko)移动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;
}
?>