Home > Backend Development > PHP Tutorial > Advanced Web Technology—Building a Website with PHP_PHP Tutorial

Advanced Web Technology—Building a Website with PHP_PHP Tutorial

WBOY
Release: 2016-07-13 17:21:42
Original
816 people have browsed it

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.

This news has 2 pages in total, currently on page 1 1 2

〈HTML〉
 〈HEAD〉〈TITLE〉Test〈/TITLE〉〈/HEAD〉

 BODY〉

 〈?PHP $string = 'world!'; ?〉

 〈H1〉Hello,〈?php echo $string ?〉〈/H1〉

 〈/BODY〉

 〈/HTML〉 

  The PHP code embedded in the HTML web page needs to end with a tag. The page above will display the results for Hello, world!. It can be seen here that the PHP program syntax is very similar to C or Perl. In fact, PHP is derived from C and Perl and supports most of the syntax and operators of C and Perl, so using PHP is very simple for both C and Perl programmers.


■Choose PHP

Although PHP has become very popular, very few people in China know about it. This is of course because it is not a commercial software and lacks market operation. Even among people who have heard of PHP, many people also hold this view. PHP has neither the support of commercial companies nor commercial graphical development tools. Can PHP have the same future as commercial software such as ASP? Indeed, ASP has quickly become very popular due to the support of Microsoft. Now bookstores are full of ASP-related books, but few books introducing PHP can be found, which illustrates this popular trend in China. However, the fact that PHP users have grown steadily across the Internet over the past year is diametrically opposed to these views. I think those who don’t value PHP have at least ignored the following reasons:

 1. PHP has proven to be a very practical software with very high performance, reliability and stability. To borrow a metaphor from martial arts novels , PHP is like a reckless hero who came from the lower class of the world and became famous step by step, while commercial software is like a young knight of noble birth. The reason for his fame is closely related to his master and sect. PHP has various data types and supports complex text processing. It even supports object-oriented and can be configured to process XML, etc.; more importantly, these functions of PHP are very practical. You must know that PHP developers are If you develop it voluntarily according to your own needs, its functions must have practical uses. Although it cannot be said that PHP is better than similar products, its strength cannot be ignored.

 2. PHP is a cross-platform product. It can run on a variety of Unix and Windows NT, and can access a variety of different databases. For many people, this is very important. Commercial products are often very demanding and can only work with specific operating systems and databases. And people like to use operating systems, web servers and databases they are already familiar with, such as Linux, Apache and MySQL.

3. PHP is an open source software. Many people do not agree with this. However, they ignore the Apache server, which accounts for 58% of the Web server market, and open source operating systems such as Linux and FreeBSD. Open source software combined creates a very effective solution.

 4. Even without considering the source code, PHP does not require any fees and is unmatched by commercial software. Although ASP is also free, many people ignore the cost of running Windows NT and MS SQL. PHP cooperates with Linux/FreeBSD, Apache, and MySQL, and there is almost no software cost. If piracy is not considered, how many people are currently using it? Will you still stick to ASP?

 5. PHP has good technical support, which can be obtained through email, forums, web pages, IRC, etc. This sounds funny. Isn't this more effective than technical support for commercial software? In fact, based on my personal experience in using commercial software and open source software, this form of technical support is quite good. Imagine, can you get technical services from the ASP development team? I think the more common outcome is that after an 800 call, all you get is a bunch of useless advice, and you finally get tired of the bouncing around. Even if it's on-site service, maybe an engineer is reinstalling the system over and over again until the system accidentally runs normally. In this way, the system administrator can at least take a break pretending not to understand anything. Open source code allows you to propose phenomena closer to the essence of the fault. Not only users who have encountered the same phenomenon will provide help, but PHP developers can also provide help. What technical support is more effective than the help provided by hundreds of thousands of users, most of whom are veterans of using PHP.

In any case, commercial support is not a necessary condition for a software to be popular. The reverse is true. The most recent example is that Linux received commercial support because of its popularity. For example, the latest version of web page creation tool DreamWaver 3.0 also begins to support PHP tags, allowing PHP code to be written directly in it. More and more domestic web developers are beginning to turn their attention to

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532430.htmlTechArticleWhen building a website, most of the time you not only need it to be able to provide static web page access, but also hope that it can Can interact with browser users and access the backend database to provide real-time updates...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template