Advanced Web technology-PHP website construction

Source: Internet
Author: User

When building a website, most of the time, it not only needs to provide static webpage access capabilities, but also hopes that it can interact with browser users and provide real-time updates to the background database. In a word, dynamic Web page service capability is required. In this case, do you choose the traditional CGI Mode, or choose PHP, ASP, and other server-side scripts?

■ From CGI to server scripts

The standard method for creating dynamic Web pages is CGI, which allows the Web server to run a CGI program to respond to browser requests. Apart from complying with simple CGI standards, CGI program development is no different from general program development. However, with the increase in the number and complexity of dynamic web pages to be generated, this approach has encountered difficulties.

The CGI program consists of two main parts: program code and HTML document content to be output, which can be called HTML code. The earliest Web developers were both programmers and Web designers, but the pages at that time were relatively simple. The developers were most concerned with the issue of program code, and the page code basically did not need to be adjusted too much. With the development of technologies including DHTML and javascript, the page can be designed very complex. Due to the emergence of various CGI libraries, the program code becomes much simpler. In this way, every time the Page code is adjusted, the CGI program needs to be changed, so that in the final CGI program debugging, the workload of debugging HTML code exceeds the workload of debugging program code. This shows that in Web development, the importance of HTML code is already very obvious, making the traditional CGI program centered on Program Code no longer the most suitable dynamic Web page processing method.

As a result, many programmers are tired of adjusting HTML code. Especially with the commercialization of the Internet, writing CGI programs and designing HTML pages have become two different occupations. To solve this problem, the programmer first uses the template file method to separate the program code from the HTML code. The CGI program reads the template file to obtain the HTML code, in this way, you do not need to change the CGI program when making minor adjustments to the page.

Basically, Each programmer uses a custom template in his own CGI program. However, if a common HTML template is used for preprocessing, does this greatly reduce the workload of programming? The simplest template can complete the interpretation by replacing the pre-defined variables in the template. Because this program is simple and effective, it is integrated into the Web server, to provide higher efficiency than CGI programs, this is the earliest server-side script.

These early server-side scripts, such as SSI that appeared in ncsa httpd, only include the concept of variables, but do not have the concept of control statements. Later, different program developers re-developed scripts that support control statements and even subprograms, so that these programs can not only serve specific dynamic web pages, but also program, as a result, CGI programs can complete all the work and become a new programming language. Because of performance, these programs are merged into the Web server itself, which becomes a new form of Web development.

■ PHP from open resources

Currently, server-side scripts are already a common method for developing dynamic web pages. Although CGI is still flexible, it is easier and more convenient to use server-side scripts. However, unlike CGI, server scripts do not have a uniform standard. Different server scripts use their own syntax. Currently, Active Server Pages (ASP), ColdFusion, Java Servlets, and Personal Home Page (PHP) are commonly used. These technologies include software supported by large companies, such as ASP, and open-source software developed through the Internet, such as PHP.

PHP is such a server-side scripting language. It was first written by Rasums Lerdorf, but a simple CGI program written in Perl, used to record visitors accessing their own web pages. Later, it was rewritten in C language and expanded to access the database. During this period, many people asked Rasums Lerdorf for a copy of the program for their own use. Rasums Lerdorf wrote some documents about the program and released PHP v1.0. In the future, more and more people are using PHP and are strongly demanding to add some other features, such as loop statements and array variables. At this time, some other programmers are also involved in the compilation of PHP source code, PHP was rewritten, and PHP v3.0 appeared. Currently, more than 0.8 million of PHP websites are being used, and the number of PHP websites is continuously increasing.

In addition to sending dynamic Web pages to browsers, PHP can also send different HTTP header identifiers so that it can provide the ability to relocate webpages, combine security authentication with Web servers, and set cookies. PHP can directly connect to a variety of databases, including MySQL, Sybase, Informix, Oracle, and MsSQL. It also supports ODBC. And supports session management and XML processing through additional libraries (these libraries are basic libraries and are also the basic configuration of PHP users ). From this we can see that PHP is no longer a simple server-side script. According to David Medinets, author of PHP3 browser application programming, PHP is an application server. Because it includes not only a complete programming language, but also the ability to access the database and support Internet protocols (such as email and HTTP, this complete set of technologies enables PHP to interact with ASP, ColdFusion, and WebSphere for a long time.

To run PHP, we usually use Linux or FreeBSD as the operating system and Apache as the Web server. Of course, it is also feasible to use other operating systems, because PHP is a cross-platform software, which of course benefits from its open source software. However, if you do not use the Apache server, PHP can only run in CGI Mode, so you cannot use the performance advantage of compiling PHP into Apache. After you download the latest PHP version from www.php3.net and complete the installation and configuration, you can use the editor or web page creation software to compile PHP code. If you can use C or Perl for programming, you will find that PHP programming is not complex. PHP as a programming language is simpler than C and easier to understand than Perl. The following is a simple page for embedding PHP programs.

There are two pages in this news. Currently, there are two pages in page 1st.


<HTML> 〉
<HEAD> <TITLE> Test </TITLE> </HEAD> 〉

<BODY> 〉

<〈? PHP $ string = 'World! ';? > 〉

<H1> Hello, <,〈? Php echo $ string? > </H1> 〉

</BODY> 〉

</HTML> 〉

The PHP code embedded in an HTML webpage must end with a mark. The above page will show Hello, world! . It can be seen that the PHP program syntax is very similar to C or Perl. In fact, PHP comes from C and Perl and supports most of C and Perl syntax and operators. Therefore, using PHP is very simple for C and Perl programmers.


■ Select PHP

PHP is very popular, but few people know it in China, of course, because it is not a commercial software and lacks market operation. Even many people who have heard of PHP have such ideas that PHP neither has the support of commercial companies nor lacks commercial graphical development tools, can PHP be as promising as ASP and other commercial software? Indeed, with the support of Microsoft, ASP has rapidly become very popular. Currently, bookstores are full of ASP-related books, and few books can be found to introduce PHP, it illustrates this popular trend in China. However, the fact that PHP users on the Internet have grown steadily over the past year is totally different from those views. I think those who do not value PHP should at least ignore the following reasons:

1. PHP has proved to be a very practical software with high performance, reliability, and stability. With a metaphor from martial arts novels, PHP is like a hero from the lower layers of the rivers and lakes, commercial software is like a noble young chivalrous man. The reason for its fame is closely related to its masters and sects. PHP has various data types and supports complex text processing. It even supports object-oriented and can be configured to process XML. More importantly, these functions of PHP are very practical, you must know that PHP developers develop PHP based on their own needs. The functions provided by PHP must be of practical use. Although PHP is better than similar products, its strength cannot be ignored.

2. PHP is a cross-platform product that can run on a variety of Unix and Windows NT and access a variety of different databases. This is very important for many people. Commercial products are usually demanding and can only work with specific operating systems and databases. People prefer to use familiar operating systems, Web servers, and databases, such as Linux, Apache, and MySQL.

3. PHP is open-source software, and many people disagree with this. However, they ignore Apache servers that account for 58% of the Web server market, and ignore open-source operating systems such as Linux and FreeBSD, these open source software are combined to form a very effective solution.

4. Even if the source code is not taken into account, PHP does not require any fees and the features cannot be compared with commercial software. Although ASP is free, many people ignore the cost of running Windows NT and ms SQL. PHP and Linux/FreeBSD, Apache, and MySQL work with each other, and almost no software fee is required, if piracy is not considered at present, how many people will stick to ASP?

5. PHP has good technical support and can be obtained through email, forum, webpage, IRC, etc. It sounds a bit funny, isn't it more effective than commercial software technical support? In fact, according to my personal experience in using commercial software and open source software, this form of technical support is quite good. Imagine that you can get technical services from ASP development group? I think the more common result is that after a 800 call, you get a bunch of useless suggestions. Finally, you get tired of making a call. Even on-site service, it may be that an engineer reinstalls the system over and over again until the system runs normally by accident, the system administrator can at least pretend to be ignorant and take a break. The Open Source Code allows you to propose a phenomenon that is closer to the essence of failure. Not only can users who have encountered the same phenomenon provide help, But PHP developers also provide help. What technical support is more effective than hundreds of thousands of users, most of whom are skilled PHP users.

In any case, commercial support is not a necessary condition for the popularity of software. In turn, it is true. In recent cases, Linux has not been commercially supported because of its popularity? For example, DreamWaver 3.0, the latest version of the web page creation tool, also began to support PHP marking and allowed PHP code writing directly in it. More and more domestic Web developers are starting to look

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.