Search code examples
androidiosmobilewindows-phone-8.1user-agent

Which other mobile browser user agents pretend to be Android and/or iPhone?


I've written a serverside script that detects the user agent of the client, then does one of three things:

  1. If it's an iOS device, send them to the Apple App Store
  2. If it's an Android, send them to Google Play
  3. Otherwise, send them to our website

It was working fine until recently, when a Windows Phone 8.1 user came along - the IEMobile 11 browser for which had this user agent:

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

I've now updated my script (see below) with an initial if condition to take care of this Windows Phone 8.1 IEMobile 11 browser, but I wondered if anyone knew of any other common mobile browsers (non-iOS and non-Android) that also included "Android" or "iPhone", "iPad", etc. in their user agent strings (so I can update my script accordingly)?

<?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;
}
?>

Solution

  • There is Tizen, a Linux based mobile OS, that uses

    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

    The emerging Firefox OS seems to do this also

    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

    I also found this list which might be useful but is laborsome to go through manually :)