Working on a website for my company, I discovered the need for wireless access to my email, stocks and such. Not wanting to pay someone else to give me this information, I decided to develop a wireless site. The information to do this is available on the internet, but it is scattered and hard to come across. I needed the ability to run php scripts, access databases, and other functions that I needed PHP to do for me. This article covers the basics of wml, how to set up your apache server, and php. Covering the basics allows you to set up this environment and then learn the rest on your own.
You will need a little experience with the Apache Web Server, Php and html. As for system requirements, I am using apache 1.3.9, php3, and Red Hat Linux 6.0 for this demonstration. I don't see any problems with setting this up on a windows machine running Apache, and PHP3 or PHP4.
In this article, I am going to walk you through the following areas; intro to wml, setting up apache for wireless appications, and creating your first WML/PHP page. Much of this information has been gathered from across the internet, and some I learned as I tried to put together a working site.
Intro to WML
WML stands for Wireless Markup Language. WAP phone or similar devices are used to view pages written in WML. WML is similar to XML based on it's syntax and scrictness. Anybody who has used html will have no problem learning WML. Many tags and attributes are the same, but there are fewer tags. WML allows the programmer to use variables that allow you to create dynamic content, although for this article we are going to use php as the dynamic language.
WML Basics
In WML you can use many sub-pages (called 'cards') in one WML page (called a 'deck'). Each WML card works like a web page and its content is displayed to the user. The following will be our first example of a .wml page. On my server, I saved this file in ~/wireless/home.wml.
<card id='home'>
My first Test page
Unlike HTML, if you do not close your tags, e.g. <wml> </wml> then, your script will not compile correctly. The example above will create a simple test message on any wireless device that says "My first Test page".
Setting up Apache
Ok, now the fun part. In order for apache to catch what a wireless device visits your server, you need to set up your httpd.conf ( my file is located in /etc/httpd/conf/ ) file, I am using PHP3 so all changes are made accordingly. Before you start you may want to make a backup copy of your httpd.conf file, just in case :)
Step 1: First, we need to use the AddType function to add a new mime type. You need to go to to the script where you define php. It looks something like below:
<IfModule mod_php3.c>
  AddType application/x-httpd-php3 .php3 .php .phtml
  AddType application/x-httpd-php3-source .phps
Needs to be changed to:
<IfModule mod_php3.c>
  AddType application/x-httpd-php3 .php3 .php .phtml .wml
  AddType application/x-httpd-php3-source .phps
This will use the php compiler on all .wml pages it encounters.
Step 2: Uncomment the apache Load Module and Add Module
#LoadModule rewrite_module 	modules/
#AddModule mod_rewrite.c
LoadModule rewrite_module 	modules/
AddModule mod_rewrite.c
Step 3: We'll use apache mod_rewrite module (only available in version 1.2+ ). Using this, you can rewite requested URL's on the fly, as certain conditions are met. You need to place this code snipplet at the bottom of the page.
RewriteEngine On
# Catch most WAP browsers
RewriteCond %{HTTP_ACCEPT} text/vnd\.wap\.wml [OR]
# WinWAP, WAPjag
RewriteCond %{HTTP_USER_AGENT} wap [OR]
#Nokia emulators (sdk)
RewriteCond %{HTTP_USER_AGENT} 7110 
# Rewrite to where your wireless page is located
RewriteRule ^[\./](.*)$ /home/mydirectory/wireless/home.wml [L]
Now, you will need to restart the apache server.
Creating your first WML/PHP wireless page
Ok, now that we have everything set up, lets create our first page. In order for a wireless device to access a page compiled using php, you need to send the correct header information.

# Send the header information<br>
header("Content-type: text/vnd.wap.wml"

# put in the wml code 
<card id='home'>
My first test page
You have just completed your first 'simple' wireless page. Now, let's try to do something just a little harder.
You need to check your site using a WAP-compatible device. I use the Software Development kit, which contains the UP.Simulator, to check my wireless pages. It allows the user to choose different phones and see what their wireless pages look like through the different devices.
A more indepth article can be found at here.
To view what this tutorial accomplished, go to using your wireless device or browser.
More information can be obtained through the following resources:
我是用 Apache架設server , 然後在mine type中加入以下參數
     text/vnd.wap.wml .wml
  image/vnd.wap.wbmp .wbmp
  application/vnd.wap.wmlc .wmlc
  application/vnd.wap.wmlsc .wmlsc


    Frank 發表在 痞客邦 留言(0) 人氣()