When building a website, most of the time it is not only required to provide static web page access capabilities, but also to interact with browser users, access the backend database to provide real-time updated information, etc. In a word, it is necessary to provide dynamic web page services. ability. At this time, should you choose traditional CGI, or server-side scripts such as PHP and ASP?
■ From CGI to server-side scripting
The standard way to create dynamic web pages is CGI, which allows the web server to run a CGI program in response to the browser's request. Apart from complying with simple CGI standards, the development of CGI programs is no different from the development of ordinary programs. However, this approach encounters difficulties as the number and complexity of dynamic web pages to be generated increases.
CGI program includes two main parts, one is the program code, and the other is the content of the HTML document 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. Developers were most concerned about program code, and the page code basically did not require much adjustment. With the development of technologies including DHTML and JavaScript, pages can be designed to be very complex, and due to the emergence of various CGI program libraries, program codes have become much simpler. In this way, every time the page code is adjusted, the CGI program needs to be modified, so that in the end, in the CGI program debugging, the workload of debugging the HTML code exceeds the workload of debugging the program code. This shows that in Web development, the importance of HTML code has become very obvious, making the traditional CGI program centered on program code no longer the most suitable way to process dynamic web pages.
In this way, quite a few programmers are tired of this kind of work of adjusting HTML code. Especially with the commercialization of the Internet, writing CGI programs and designing HTML pages have become two different professions. In order to solve this problem, programmers first used a template file method to separate the program code and HTML code. The CGI program read the template file to obtain the HTML code, so that when making minor adjustments to the page, there was no need to modify the CGI program. .
Basically every programmer uses customized templates in their own CGI programs. However, if there is a universal HTML template and a universal program is used for preprocessing, this will greatly reduce the program design workload? The simplest template can complete the interpretation work by replacing the predefined 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. end script.
These early server-side scripts, such as the SSI that appeared in ncsa httpd, only included the concept of variables, but no concept of control statements. Later, different program developers redeveloped script interpretation processing programs that supported control statements and even subroutines, so that these programs could not only serve specific dynamic web pages, but also be capable of programming, and thus be able to complete everything that CGI programs can do. Work has become a new programming language. Also for performance reasons, these programs were incorporated into the web server itself, making it a new form of web development.
■ PHP from open resources
Currently, server-side scripting is a common way to develop dynamic web pages. Although CGI still has the advantage of flexibility, in general, server-side scripting is used Easier and more convenient. However, unlike CGI, there is no unified standard for server-side scripts, and different server-side scripts use their own syntax. Currently the more commonly used ones are: Active Server Pages (ASP), ColdFusion, Java Servlets, Personal Home Page (PHP), etc. These technologies include both software supported by large companies, such as ASP, and open source software developed through cooperation through the Internet, such as PHP.
PHP is such a server-side scripting language. It was originally written by Rasums Lerdorf. It is just a simple CGI program written in Perl language to record visitors to his own web pages. . Later it was rewritten in C language, and the scope was expanded to access databases. During this period, many people asked Rasums Lerdorf for a copy of this program for their own use. Rasums Lerdorf wrote some documents introducing this program and released PHP v1.0. Later, more and more people used PHP and strongly requested to add some other features, such as loop statements and array variables. At this time, some other programmers also began to participate in the writing of PHP source code and re-written PHP. PHP v3.0 appeared. Currently, there are more than 800,000 websites using PHP, and the number is still increasing.
In addition to sending dynamic web pages to the browser, PHP can also send different HTTP header identifiers, allowing it to provide web page relocation, the ability to combine with the security authentication of the web server, and set cookies. PHP can provide the ability to directly interconnect with a variety of databases, including MySQL, Sybase, Informix, Oracle, MsSQL, etc., and can also support ODBC.And can support session management and XML processing through additional libraries (these libraries are basic libraries and therefore also the basic configuration for PHP users). From here we can see that PHP is no longer a simple server-side script. According to David Medinets, the author of "PHP3 Browser Application Programming", PHP is an application server. Because it not only includes a complete programming language, but also includes the complete ability to access databases and support Internet protocols (such as email and HTTP). This set of technologies makes PHP shorter than ASP, ColdFusion, and WebSphere. long.
To run PHP, Linux or FreeBSD is usually used as the operating system and Apache as the web server. Of course, it is also feasible to use other operating systems. This is because PHP is a cross-platform software, which of course benefits from the fact that it is open source software. However, if you do not use the Apache server, then PHP can only run in CGI mode, so you cannot take advantage of the performance advantages of compiling PHP into Apache. After downloading the latest version of PHP from www.php3.net and completing the installation and configuration, you can use an editor or web page creation software to write PHP code. If you can program using C or Perl, you will find that PHP programming is not complicated. As a programming language, PHP is simpler than C and easier to understand than Perl. The following is the simplest page embedding a PHP program.
〈HTML〉