我已經寫了檢測客戶端的用戶代理服務器端腳本,然後做的三兩件事之一:哪些其他移動瀏覽器用戶代理假裝爲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;
}
?>