Using PHP to create a WML page
If you have decided to have a WAP version of your website and you want to make it dynamic, you can use PHP to generate your WML pages. In order to view WML pages you should download and install a phone emulator from Phone.com, Nokia.com or somewhere else. You can also use a WAP enable cell phone.
You should first make sure that the server your website is on can serve WML pages. (I am assuming it to be Apache) If the server doesn't know how to handle a .wml file, you can add it your Apache configuration or create an .htaccess file that adds the file type to a specific directory.
Sample .htaccess file
addtype text/vnd.wap.wml wml
addtype image/vnd.wap.wbmp wbmp
AddType text/vnd.wap.wmlscript wmls
AddType application/vnd.wap.wmlc wmlc
AddType application/vnd.wap.wmlscriptc wmlsc
The .htaccess file adds support for wml files, wbmp image format which is read by WAP browsers, support for wmlscript files and also support for compiled wml or wmlscript files. You can configure PHP to parse WML files by adding the following to an .htaccess file AddType application/x-httpd-php .wml or httpd.conf file if you have access to it on your server. Once you've added the file types you should create a simple WML file or PHP script to make sure that the server is configured correctly.
Sample WML file
<xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml>
<?wml>
<card id="page1" title="Page 1">
<p>
Testing to make sure.
</p>
</card>
</wml>If you can view the wml deck, you then move on to using PHP to generate a page. You would use the header function to let a browser know that the page is a wml page. In the example below the header is sent then the date is printed. If you've configured PHP to recognize .wml files as scripts you could give the file a .wml extension. If PHP isn't configured to recognize .wml files, then you can name the file with a PHP script extension. As long as the correct header is sent, the WAP browser will display the file.
PHP Code
<?
// send wml headers
header("Content-type: text/vnd.wap.wml");
echo "<xml version="1.0"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
?>
<wml>
<card id="card1" title="Example 1">
<p>
<?php
// format and output date
$the_date = date("M d Y");
print $the_date;
print "<br/>Welcome to a PHP WAP-enabled site!";
?>
</p>
</card>
</wml>Note: that PHP outputs error messages as HTML, which a WML browser will not understand. The WML browser will tell you that there's an error in your wml code.
The Wireless FAQ recommends commenting the header function out:
Like so -> // header("Content-type: text/vnd.wap.wml");
to test PHP scripts in a regular HTML browser and fix any script errors that are present then uncomment the header function:
Like so -> header("Content-type: text/vnd.wap.wml");
before testing with a WML browser. This way it is more likely that any errors will be the result of a WML coding error.