WAP and domain names

It is very practical to re-use already existing HTML code, so it can be beneficial to have your first page (homepage) differentiate between a desktop HTML browser and a mobile WML browser and serve content accordingly. This allows the same URL (yourname.com) to be used to view both your HTML site and your WAP site.  


The PHP code below allows you to do just that. Implement this code into an INDEX.PHP page, before any of your site content is loaded. It will first attempt to identify what type of browser is trying to hit your site. If the PHP code identifies a WAP user from the list of possible WAP browsers, it will direct the user (seamlessly) to the specified WML pages. If it does not identify a WAP browser or any browser at all, it will redirect to your specified HTML page.


Advanced Implementation: This has to be done on the server side, and the following PHP code will first attempt to discover if the WAP gateway being used can accept the text/vnd.wap.vml MIME type. If not, it will check the first four characters in the ID string to determine if it's a WML browser. If there's no match, it's assumed that it's an HTML browser. As new WML browsers come along, their ID strings should be added to the list.


The code is based on Robert Whitinger's (robert@wapsight.com) code submitted to the PHP mailing list, with several additions for browser ID string from Don Amaro's (donamaro.concepcion@nl.unisys.com) log files.




Example code:


 // Because this script sends out HTTP header information, the first characters in the file must be the <? PHP tag.

  $htmlredirect = "/html/my_htmlpage.html";                          // relative URL to your HTML file

  $wmlredirect = "http://wap.mysite.com/wml/my_wmldeck.wml";         // ABSOLUTE URL to your WML file  

  if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0) {        // Check whether the browser/gateway says it accepts WML.

    $br = "WML";


  else {


    if($browser=="Noki" || // Nokia phones and emulators

      $browser=="Eric" || // Ericsson WAP phones and emulators

      $browser=="WapI" || // Ericsson WapIDE 2.0

      $browser=="MC21" || // Ericsson MC218

      $browser=="AUR " || // Ericsson R320

      $browser=="R380" || // Ericsson R380

      $browser=="UP.B" || // UP.Browser

      $browser=="WinW" || // WinWAP browser

      $browser=="UPG1" || // UP.SDK 4.0

      $browser=="upsi" || // another kind of UP.Browser ??

      $browser=="QWAP" || // unknown QWAPPER browser

      $browser=="Jigs" || // unknown JigSaw browser

      $browser=="Java" || // unknown Java based browser

      $browser=="Alca" || // unknown Alcatel-BE3 browser (UP based?)

      $browser=="MITS" || // unknown Mitsubishi browser

      $browser=="MOT-" || // unknown browser (UP based?)

      $browser=="My S" ||                       // unknown Ericsson devkit browser ?

      $browser=="WAPJ" || // Virtual WAPJAG www.wapjag.de

      $browser=="fetc" || // fetchpage.cgi Perl script from www.wapcab.de

      $browser=="ALAV" || // yet another unknown UP based browser ?

      $browser=="Wapa")                         // another unknown browser (Web based "Wapalyzer"?)


        $br = "WML";


    else {

      $br = "HTML";



  if($br == "WML") {

    header("302 Moved Temporarily");       // Force the browser to load the WML file instead

    header("Location: ".$wmlredirect);



  else {

    header("302 Moved Temporarily");       // Force the browser to load the HTML file instead

    header("Location: ".$htmlredirect);