Home  >  Article  >  php教程  >  WML,Apache,和 PHP 的介绍

WML,Apache,和 PHP 的介绍

WBOY
WBOYOriginal
2016-06-13 12:40:49802browse

在公司的网站中, 我发现需要一个可以无线接收我的电子邮件,股市资讯等. 不想要付钱给人来得到我要的资讯, 我决定了开发一个无线网站.这样的资讯在网际网路上是没问题的,但是它被分散得难以收集。我需要可以执行 php ,存取资料库,并且我需要 PHP 为我做另外的功能。这篇文章含盖了wml 的基础, 如何建立你的 apache Server 和 php 。这些基础可让你建立环境并且自己学习往後的应用.
 

需 求
你要对 Apache Web Server, Php 和 html 有点经验. 对系统的要求来说,我是用 apache 1.3.9, php3, 和 Red Hat Linux 6.0 来示范. 我还没碰到在 windows 上跑 Apache, 和 PHP3 或 PHP4 上的任何问题.

在这篇文章,我将指导你接触的领域: wml 的介绍,在 Apache 上设定无线 appications ,并且建立你的第一个 WML/PHP 网页.大部份的资讯可从网际网路上收集.

WML 简 介
WML 代表无线的标注语言. WAP 电话或类似的设备被用来以 WML 写成的网页。WML 基于它类似於 XML 的句法和 scrictness 。使用过了 html 的任何人将不有问题学习 WML 。许多标签和属性是一样的,况且标签不多. WML 允许程式开发者开发动态的内容, 尽管为这篇文章我们将以PHP作为动态的语言.

WML 基 础
在 WML 你能使用许多子页 ( 叫 "cards'' ) 在一个 WML 页中 (叫 " deck") .每个 WML card 的作用像在网页中被显示的内容.下列将是我们 .wml 页的例子 。在我的 Server 上,我在 ~ /wireless/home.wml 储存了这个档案

 
   

我的第一个测试页


   
   

不同于 HTML ,如果你不colse 标签, 例如 ,则你的程式码将不正确. 此例子会在任何无线的设备上产生一简单的测试信息“我的第一个测试页”。

设 定 Apache
好, 现在有趣的部分.为了 apache 能 catch 住无线设备到访你的Server, 你需要建立你的 httpd.conf ( 我的档案位於 /etc/httpd/conf/) 档案, 我用 PHP3 因此所有的变化会被记录。在你开始以前,你可以备份你的 httpd.conf 档案,以防万一:)

步骤 1 :第一, 我们需要 AddType 功能增加一新的 MIME 类型。你需要到你定义 php 的 Script 中。看起来像下面一样:


AddType application/x-httpd-php3 .php3 .php .phtml

AddType application/x-httpd-php3-source .phps



要改为:

 


AddType application/x-httpd-php3 .php3 .php .phtml .wml

AddType application/x-httpd-php3-source .phps


这会用 PHP compiler 在所有的 .wml 页.

步骤 2 :去除Mark(Uncomment)apache Load Module 和 Add Module

变更:


#LoadModule rewrite_module modules/mod_rewrite.so

#AddModule mod_rewrite.c
 

成:

LoadModule rewrite_module modules/mod_rewrite.so

AddModule mod_rewrite.c


步骤 3 : 用 apache mod_rewrite module (只适用 1.2+版以上 ). 用这个,你可以即时的 rewite requested URL(当条件符合时). 需要把这片断码放在网页的底部.

 

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]


现在要重新启动 apache server.

 

产生你第一个无线 WML/PHP 网页
Ok, 既然我们万事俱备, 让我们建立第一个网页。为了能正常运作,你需传送正确的 header 资讯.

# Send the header information

header("Content-type: text/vnd.wap.wml");

?>

# put in the wml code






My first test page





你刚完成了你的第一个“简单”的无线网页。现在, 让我们试著更努力做一些较难的东西吧。  

你需要检查你 WAP 兼容的网站设备。我使用 Phone.com 软件开发工具包, 它包含 UP.Simulator , 可以检查我的无线网页。选择不同的电话并且看他们的无线网页通过不同的设备时看起来的长像。


更多的资讯在:

http://updev.phone.com
http://www.wapforum.org
http://www.wap.com
http://www.waplinks.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn