2

How do I differentiate between Midp 2.0 and 2.1 and Android from a WAP browser so as to redirect them to different location to download the app corresponding to their mobile.

Akhil K Nambiar
  • 3,835
  • 13
  • 47
  • 85

1 Answers1

2

It's pretty difficult to catch all cases correctly, and anyone can always just set their User-Agent to a different value, but the general way to do it in php is:

  1. Automatically, with get_browser(), which requires an up-to-date version of browscap.ini

    $browserInfo = get_browser();
    if($browserInfo->platform === "Android")
    {
        // deliver Android link
    } else if($browserInfo->platform === "JAVA") { // MIDP
        // deliver MIDP link
    }
    
  2. Manually, by running a bunch of regex strings against $_SERVER['HTTP_USER_AGENT']. Very generic matches could be done on .*MIDP.* and .*Android.* if you want to do it this way.

    if(preg_match("/.*Android.*/", $_SERVER['HTTP_USER_AGENT'])) // Android
    {
         // deliver Android link
    } else if(preg_match("/.*MIDP.*/", $_SERVER['HTTP_USER_AGENT'])) { // MIDP
         // deliver MIDP link
    }