Introduction to WAP using WML, ASP and PHP

    May 13, 2003

By Jean-Baptiste Minchelli

As technology changes, so do the tools that we use to manipulate it. Today the Internet is available from a number of devices, both connected and portable.

WAP (Wireless Application Protocol) is a specification from the WAP Forum that determines the standards and protocols that can be used to transfer data across wireless devices including cell phones, PDA’s, and portable computers. The WAP Forumis an industry-wide consortium, which aims to define how applications should operate within the Wireless domain.

At the time of writing, WAP version 2.0 has just become a standard, so I thought that this article would be a great idea to show those of you who’ve never played around with WAP just what it can do and how easy it is to create WAP compatible content using WML, ASP or PHP.

In this article we will look at using the free OpenWave SDK to test some WML and WMLScript using a WAP emulator. We will also look at how to configure both IIS and Apache web servers so that they are capable of sending WML documents to any WAP compatible device that requests them.

To test the samples in this article, you should download and install the OpenWave SDK for Windows. You should also have either one/both of the following setup:

  • A Windows 2000 server running IIS
  • A Windows 2000/Linux/Unix server running Apache

[Note]This article will not focus on teaching you WML directly, but rather it will show you the steps you need to take to implement and test WML scripts using a web server and WAP emulator. There are several links at the end of the article if you’re interested in learning WMLScript in its entirety. [End Note]

Configuring IIS and Apache

When a web server receives a request for a document, it will retrieve that documents MIME type and append it to the returned document as part of its header information. These MIME types can be configured, and both IIS and Apache facilitate adding new MIME types.

WML (Wireless Markup Language) files make up the bulk of WAP content, and are plain text files that use markup tags in a similar way to HTML and XML. They contain the .wml file extension, and before we can request a WMLScript from our web server, the server needs to know its MIME type.

Let’s now look at adding the necessary MIME types for both Apache and IIS.

For Apache

For Apache, you need to edit the httpd.conf file (which contains Apache’s configuration directives) and add the following lines to the end of the file:


The AddType directive tells Apache the details of the MIME types for files with specific extensions. The AddType directive is used like this:


We’ve just added five new MIME types to Apache’s httpd.conf file. If we now create a blank file called test.wml, then when we request this file through a WAP device, Apache will set the MIME type of that request to text/vnd.wap.wml, which indicates that the file contains WMLScript.

You’ll need to restart Apache so that it recognizes our newly added MIME types.


Start the Microsoft Management Console (Start -> Run -> MMC) and load the IIS snap-in from the c:winntsystem32inetsrviis directory. Right click on the node that matches the name of your web server and choose the properties option.

Click on the edit button next to the master properties drop down box, select the HTTP Headers tab, and click on the file types button:

This will load the registered file types dialog. Click on the new type button and create five new file types using the list shown below:

  • Associated extension: wml
  • Content type: text/vnd.wap.wml
  • Associated extension: wmls
  • Content type: text/vnd.wap.wmlscript
  • Associated extension: wmlc
  • Content type: application/vnd.wap.wmlc
  • Associated extension: wmlsc
  • Content type: application/vnd.wap.wmlscriptc
  • Associated extension: wbmp
  • Content type: image/vnd.wap.wbmp

Click OK three times to close all of the open dialogs, and then close MMC itself. You will need to restart IIS so that it picks up our newly added MIME types.

[Note] We don’t have to set the MIME types for WAP content in IIS/Apache, and we can add the details of the MIME type manually to a script using by modifying its header information. [End Note]

Now that our Apache/IIS web server is ready to handle requests for WAP content, let’s create a simple “hello world” script using WML and WMLScript.

Hello World in WMLScript

WAP currently uses WML (Wireless Markup Language), which is based on XML (eXtensible Markup Language), and WMLScript, which is based on ECMAScript.

If we compare WML to a Web application, we could say that WML plays the role of HTML (document formatting), and WMLScript is like JavaScript (implemented in the same way as a client-side scripting language).

The WAP Forum has just released version 2.0 of the WAP standard. This release includes support for 3G (third generation) wireless networks, as well as XHTML based client side languages. Enough about that however, I will go into more about the WAP standard and its governing architectures in another article.

Using notepad, create a new file named hello.wml and save it in a directory that can be processed by either your IIS or Apache server. Enter the following code into hello.wml:


Create another file called hello.wmls and save it in the same directory as hello.wml. Enter the following code into hello.wmls:


At this point we’ve configured our web server, and we’ve also create two WML-based scripts. Load the OpenWave SDK and enter http://localhost/hello.wml into the address bar, replacing localhost with the name/IP address of your web server.

Click on the go button or press enter. OpenWave will contact our web server and request hello.wml, which displays “Hello in WMLS” on the WAP emulator that comes bundled as part of the OpenWave SDK. Hello.wmls also displays the same text, but is a browser result of executing the .wmls script.

Here’s how the output looked on my screen:

As you can see from my screen shot, I’ve loaded hello.wml into the OpenWave IDE and ran it from there, which you can do also. Notice in the lower frame that OpenWave formats the WML as well-formed XML, showing us that WML is indeed based on XML.

You don’t have to use the OpenWave IDE to test your WML. If your web server is connected to the Internet then you can use a WAP-enabled device to call up your WMLScript and it will be displayed exactly how it is in OpenWave.

Before we move on to see how we can generate WML dynamically using PHP and ASP, let’s talk a bit about the code that makes up our hello.wml script.


A valid WML document must start with a line corresponding to the DTD matching the WML implementation currently used in the document. We’ve used the XML-based WML DTD, which exists on the server.

WML has been created for the wireless world: low bandwidth, small screen and non-ergonomic devices. It’s for this reason that we have to deal with decks and cards, which are the proper names for the contents of a WML document.

A deck is a succession of cards (screens), which provides navigation options for the user. WML is retrieved differently that HTML is from a server, because multiple WML pages are retrieved in one (downloaded) document. During the navigation through the deck, clients don’t have any interaction with the server. In our example, we have created just one card in the deck.

[Note] The id of each card must be unique in the deck, because this id allows navigation between cards. [End Note]

Our hello.wml script calls hello.wmls. User interaction with the WMLScript is achieved by using a <do> element. When the WMLScript parser reaches the <go> element, it retrieves the contents of its href attribute, which is hello.wmls.

If you take a look at the code in hello.wmls, you will see that it resembles JavaScript/C++ code. The Dialogs.alert() function simply outputs a string to the WAP device, which in our case is the OpenWave emulator.

In hello.wml, we call the Display function (which is part of hello.wmls) by adding a hash character, function name, and single string argument after the URL for the href attribute of the <go> tag:


As I’m sure you’ll agree, this is a very smart way to invoke functions from other WML scripts. Because WMLScript is client-side, it’s useful for simple calculations and manipulations, such as currency conversion and so on. WML also has a method for passing information (variables) between cards, however that’s outside the scope of this article.

Generating WMLScript with PHP and ASP

It’s possible (and extremely easy) to add dynamic content to our WMLScripts using PHP or ASP. As I mentioned earlier, as long as our PHP/ASP scripts output WML only, then they can be called through a WAP device. You don’t have to use ASP or PHP however, and you could just as easily code up a WMLScript using Perl, C#, or JSP.

Think of the possibilities that are available to us by using PHP or ASP to build our WAP applications: databasing, mail servers, LDAP, message queuing, etc. For a script to be WAP compatible, it must output a WML header to the client. It’s possible to make Apache/IIS output this header when it receives a request for a WML file, but we can also manually output this header using either ASP or PHP.

Here’s some PHP code that generates WML to output the date:


Here’s some ASP code that generates exactly the sample WMLScript:


It’s crucial not to omit the content type information from the top of each script. It’s this information that enables the different agents in the protocol to correctly process the message (gateway, browser, etc). The rest of the code is conventional; you insert the ASP/PHP code inside the WML code. You can therefore carry out any processes you want (database access, image generation, etc).

Here’s how the output looked in the OpenWave WAP emulator on my PC:


As you can see from the examples in this article, we’ve quite easily developed our first wireless application using WML, ASP, and PHP.

Wireless applications offer some degree of speciality, meaning that not all web sites will find their niche within the wireless technology market. On the other hand, you need one version of you site as HTML for normal web browsers, one for WAP enabled devices (WML), and maybe even another in HTML 3.2 format for PDA’s, which can be a pain.

If you do decide to implement a WAP compatible version of your web site, then it’s clear that development and maintenance costs will quickly begin to add up.

In my next article I will show you how to deal with multi-device support for a wireless applications. Until then, take a look at the books and links below for more information on WAP, WML, WMLScript, etc.

Support Material

This article contains a support file. To download the attached support file, please click here.

DevArticles ( went “live-to-air” in November of 2001. Starting out as just a one man show ran by me from my bedroom, DevArticles quickly became one of the most popular developer sites on the ‘net. Most people attribute it to the way that we write our articles, but I’d also like to think that it’s our strong sense of community that has helped make us what we are today.