Php web server related knowledge

Source: Internet
Author: User
Tags php web server

We all know the power of PHP. We have recently learned about php web servers. Let's discuss this with you. WAP (Wireless Communication Protocol) is an open global standard for communications between digital mobile phones, personal handheld devices (PDAs), and computers. Static WAP pages cannot meet personalized service requests in many aspects. Therefore, dynamic WML pages are generated through WAP Server language, which has a wide range of application value and high commercial value.

The WAP application structure is very similar to the Internet. A typical WAP application request is as follows: first, a mobile terminal with the WAP user proxy function (such as a WAP mobile phone) use a Micro Browser that runs internally to send WAP service requests to a website wirelessly. This request is first intercepted by the WAP Gateway and encoded and compressed to reduce network data traffic. At the same time, the WAP protocol is converted to the HTTP protocol as needed, then, the processed requests are forwarded to the corresponding WAP Server. On the WAP Server, the requested page is output directly or by the server script based on the page extension and other properties, and then sent back to the user through the gateway.

The above WAP application process shows that the process of generating dynamic WAP pages is very similar to that of dynamically generating Web pages. However, because the WML language used by the WAP application comes from the strict XML syntax, the output format must be output according to the WAP webpage specification. In addition, due to the application scope of the WAP protocol and the software and hardware level of the mobile client, the size of the page output each time, the format and size of the image are limited. Let's take the PHP script language as an example to see how to dynamically output the WAP page.

1. Set up a php web Server

First, you must install PHP on your Web server to process PHP scripts. To enable the php web server to recognize and process PHP, WML, WBMP, and other files at the same time, the following file types must be added to the MIME table of the Web server.

 
 
  1. text/vnd.wap.wml .wml   
  2.  
  3. image/vnd.wap.wbmp .wbmp   
  4.  
  5. application/vnd.wap.wmlc .wmlc   
  6.  
  7. text/vnd.wap.wmls.wmls  
  8.  
  9. application/vnd.wap.wmlsc .wmlsc   

2. Use PHP to output simple dynamic WAP pages

The following is an example of the simplest php wap page generation. Note that because the PHP interpreter is required to interpret the program and output the WAP page, all similar programs should use the. php extension.

 
 
  1. <?php 
  2. header(″Content-type: text/vnd.wap.wml″);  
  3. echo (″<wml> <card> <p>″);  
  4. echo date( ″l dS of F Y h:i:s A″ );   
  5. echo (″</p></card></wml>″);  
  6. ?> 

This example can be viewed in the WAP mobile phone simulator and output the current date and time, which cannot be identified in a common browser and may even be considered as an incorrect download. This is because the output document is declared as the WML type at the beginning of the program. Only WAP devices of this type can recognize and interpret this type. It is worth noting that our common HTML languages do not have strict compliance requirements. Most browsers can "tolerate" a large number of compilation errors, while WML standards are quite strict, A single error may result in failure to output the required page.

Once we know the standard process of outputting WAP pages using PHP scripts, we can use the powerful functions of PHP in combination with the interactive processing of WML language and simple scripts of WML s notebook, developed an application system suitable for our needs.

3. Use PHP to dynamically generate images

The WAP application uses a special black/white image format WBMP. We can use some tools to convert existing images into WBMP format and then use them in WML documents. However, if the required images such as the K-line chart can be dynamically generated on the WAP site, there will be broad application prospects. Fortunately, PHP's GD library (version 1.8 or later) already provides functions.

 
 
  1. <?PHP 
  2. Header(″Content-type: image/vnd.wap.wbmp″);  
  3. Sim = ImageCreate(50, 50);  
  4. Swhite = ImageColorAllocate(Sim,255,255,255);  
  5. Sblack = ImageColorAllocate(Sim,0,0,0);  
  6. ImageRectangle(Sim, 5, 5, 20, 20, Sblack);  
  7. ImageWBMP(Sim); ImageDestroy(Sim);  
  8. ?> 

This file will display a black rectangular box in the WAP simulator. Note that to use the GD image function library, you must load the PHP_GD.DLL library file in the php web server configuration.

4. Process Chinese Characters in PHP

As a global application, WAP uses UNICODE 2.0 as its standard character set encoding so that it can simultaneously process a variety of texts, including English, Chinese, Japanese, and French. We usually use GB2312 encoding for processing Chinese characters, and different internal code standards are bound to be unavailable. Therefore, if the two encoding formats are not converted using a code table, Chinese characters may be garbled. Now there are more mature GB-2312 and UNICODE conversion procedures and functions, and in ASP, PHP, JSP and other systems, we can find them on some technical sites.

Currently, most WAP mobile phones (Nokia7110, Ericsson R320S and so on) are encoded using UTF-8, that is, UNICODE. In this way, if we use Chinese characters (GB2312 encoding) in WML, garbled characters will be generated and cannot be identified by mobile users. Therefore, before outputting Chinese characters, UNICODE must be encoded using a program or function. In a few mobile phones or WAP devices that support GB2312 encoding, we can define the document internal code type in the program to directly display Chinese characters, for example:

 
 
  1. <?Php
  2. Header ("Content-type: text/vnd. wap. wml;Charset=Gb2312″);
  3. Echo (″<Wml><Card><P>″);
  4. Echo ("Chinese test ″);
  5. Echo (″</P></Card></Wml>″);
  6. ?> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.