Home  >  Article  >  Backend Development  >  PHP and WAP_PHP Tutorial

PHP and WAP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:04:241113browse

WAP (Wireless Communication Protocol) is an open global standard protocol for communication between digital mobile phones, personal handheld devices (PDA, etc.) and computers. With the continuous development of wireless communications, static WAP pages can no longer meet user personalized requirements in many aspects. Therefore, developers can use languages ​​such as PHP on the WAP server to generate dynamic WML pages to meet user needs.

The application structure of WAP is very similar to the Internet. A typical WAP application request step is described as follows:
1. A mobile terminal with WAP user agent function (such as a WAP mobile phone), through the micro-browser running internally The server sends a WAP service request to a certain website. The request is first intercepted by the WAP gateway, which encodes and compresses the information content to reduce network data traffic. At the same time, the WAP protocol is converted into the HTTP protocol as needed.
  2. The protocol forwards the processed request to the corresponding WAP server. On the WAP server side, based on attributes such as page extension, the requested page is output directly or after being interpreted by a server-side script, and then transmitted back to the user through the gateway.
From the above WAP application process, we can find that the process of generating dynamic WAP pages is very similar to the process of dynamically generating Web pages. However, since the WML language used by WAP applications is derived from XML with strict syntax, the output format must be output according to the specifications of the WAP web page. At the same time, due to limitations such as the application scope of the WAP protocol and the software and hardware configuration of the mobile client, there are certain restrictions on the size of the page, image format and capacity of each output. In this article, the author will use PHP language as an example to discuss the method and application of dynamically outputting WAP pages with the majority of network program development enthusiasts.
Output a simple dynamic WAP page
Since the process of generating a WAP page is very similar to generating a general Web page, the author will introduce it through an example of the simplest WAP page. But a word of caution: Since a PHP interpreter is needed to interpret the program and output the WAP page, all similar programs should have "php" as the extension.
 < ?php
header("Content-type: text/vnd.wap.wml"); //Define the output document as WML type
echo (" ");
echo ( " Hello WAP" );
echo ("");
?>
This example can be browsed in the WAP mobile phone simulator and outputs a classic "Hello WAP" statement, but in ordinary network browsing The reason is very simple. The output document is declared as WML type at the beginning of the program, and only the WAP device can recognize and interpret it. However, I would like to remind you that common HTML languages ​​do not have strict normative requirements, and most browsers can "tolerantly" accept writing errors. However, WML's specifications are quite strict, and any errors may result in the inability to output the required content. page.
 Example 1 Dynamically generate images
 The image used by WAP is a special black and white image format: WBMP. Developers can use some existing tools to convert general images into WBMP format and then use them in WML documents. However, if the required images (such as the K-line chart of the stock market) can be dynamically generated in the WAP program, the program will have extremely broad application prospects. PHP provides powerful graphics drawing functions. The following example will display a black rectangular box in the WAP simulator.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445222.htmlTechArticleWAP (wireless communication protocol) is carried out between digital mobile phones, personal handheld devices (PDA, etc.) and computers An open global standard protocol for communications. With the continuous development of wireless communications, static...
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