Web technology Advanced-php Building Web site _php Tutorial

Source: Internet
Author: User
Tags php source code
When building a website, most of the time not only need it to provide static Web access, but also hope that it can interact with the browser user, access to the backend database to provide real-time updated information and so on, in a word, to provide dynamic Web services capabilities. At this point, you choose the traditional way of CGI, or choose PHP, ASP and other server-side scripts?

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 to respond to browser requests. In addition to complying with the simple CGI standard, the development of CGI programs is no different from the development of common programs. However, this approach is difficult as the number and complexity of dynamic Web pages to be generated increases.

The CGI program consists of two main parts, one is the program code and the other is the HTML document content to be exported, which can be called HTML code. The first web Developer is both a programmer and a web designer, but the pages are relatively simple at that time, the developers are most concerned about the problem of the program code, the page code basically does not need too much adjustment. With the development of technology, including DHTML, JavaScript, the page can be designed very complex, and due to the emergence of various CGI libraries, the program code is much easier. In this way, every time the page code is adjusted, the CGI program needs to be changed so that in the end of the CGI program debugging, the workload of debugging the HTML code exceeds the workload of the Debug program code. This shows that in web development, the importance of HTML code is already very obvious, so that the traditional program code-centric CGI program is no longer the most suitable Dynamic Web page processing method.

In this way, a considerable number of programmers are tired of the work of tweaking HTML code, especially with the commercialization of the Internet, writing CGI programs and designing HTML pages has become two different occupations. To solve this problem, the programmer first uses the template file method to separate the program code and the HTML code, the CGI program reads the template file to obtain the HTML code, so that when the page is small adjustment, there is no need to change the CGI program.

Basically each programmer uses a custom template in his own CGI program, however, if there is a generic HTML template that is preprocessed with a generic program, does that not significantly reduce the amount of programming effort? The simplest template can be interpreted by replacing the predefined variables in the template, and because the program is simple and effective, it is integrated into the Web server to provide a higher efficiency than the CGI program, which is the oldest server-side script.

These early server-side scripts, such as SSI, which appeared in NCSA HTTPd, included only the concept of variables, but not the concept of control statements. Later, different program developers re-developed the support control statements, and even support the subroutine script interpretation handlers, so that these programs not only for the specific dynamic Web services, but also able to program, so that the CGI program can complete all the work, become a new programming language. Also because of performance, these programs are incorporated into the Web server itself, which becomes a new form of web development.

PHP from Open source

Currently, server-side scripting is a common way to develop dynamic Web pages, although CGI still has the advantage of flexibility, but in general, it is easier and easier to use server-side scripting. However, unlike CGI, server-side scripts do not have a uniform standard, and different server-side scripts use their own syntax. Currently more commonly used are: Active Server Pages (ASP), Coldfusion,java servlets,personal Home Page (PHP) and so on. These technologies include both software that is supported by large companies, such as ASP, and open source software, such as PHP, that is co-developed through the Internet.

PHP is a server-side scripting language that was first written by Rasums Lerdorf, a simple CGI program written in Perl that records visitors to his own web pages. Later it was re-written in C and extended to access the database. During this period, a lot of people to rasums Lerdorf to the copy of the program for their own use, Rasums Lerdorf wrote some documents to introduce this program, and published PHP v1.0. Later, more and more people use PHP, and strongly demand to add some other features, such as loop statements and array variables, and other programmers also began to participate in the PHP source code, PHP was rewritten, PHP v3.0 appeared. Currently, there are more than 800,000 Web sites using PHP, and they are constantly increasing.

In addition to sending dynamic Web pages to the browser, PHP can send different HTTP header identifiers that provide Web page relocation, the ability to combine security authentication with Web servers, and set cookies. PHP provides the ability to connect directly to multiple databases, including MySQL, Sybase, Informix, Oracle, MSSQL, and so on, and can support ODBC. and through additional libraries to support session management and XML processing (these libraries are basic libraries and therefore the basic configuration of PHP users). From here we can see that PHP is no longer a simple server-side script, according to "PHP3 Browser application Programming" author David Medinets, PHP is an application server. Because it includes not only a complete programming language, but also the full ability to access the database, the ability to support Internet protocols such as e-mail and HTTP, this whole set of technologies enables PHP to interoperate with ASP, ColdFusion, and WebSphere.

To run PHP, you typically use Linux or FreeBSD as your operating system, using Apache as your Web server. Of course, it is also possible to use other operating systems, because PHP is a cross-platform software, which is of course due to its open source software. However, if you do not use the Apache server, then PHP can only be run as CGI, so you cannot take advantage of the performance benefits of compiling PHP into Apache. When the latest version of PHP is downloaded from www.php3.net and the installation is complete, you can use the editor or web authoring software to write PHP code. If you can use C or Perl programming, you will find that PHP programming is not complicated, as a program language PHP is simpler than C, easier to understand than Perl. The following is the simplest page to embed a PHP program.

This news a total of 2 pages, currently on the 1th page 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 page needs to end with a tag. The above page will show the results of the hello,world!. As you can see, 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's syntax and operators, so using PHP is a very simple task for both C and Perl programmers.


Select PHP

Although PHP is very popular, but there are few people who know it at home, it is because it is not commercial software, lack of market operation. Even in the people who have heard of PHP, many people also have this view, PHP without the support of commercial companies, but also lack of business graphics development tools, PHP and ASP and other commercial software as promising? Indeed, the ASP because of Microsoft's support, make it quickly become very popular, and now the bookstore is full of related books of ASP, and rarely find a book to introduce PHP, is to explain the domestic trend. However, the fact that PHP users have grown steadily throughout the Internet over the past year is diametrically opposed to these views. I think those who do not value PHP at least ignore the following reasons:

1. PHP has proven to be very useful software, performance, reliability, stability is very high, borrowed from a martial arts fiction metaphor, PHP is like from the lake and the bottom of a step-by-step fame of the gallant Outlaws, and commercial software is like a noble young Chevalier, the reason for its fame is closely related to his master and the door. PHP has a variety of data types and support complex text processing, it even supports object-oriented, can be configured to handle XML, and so on, more importantly, PHP's features are very practical, to know that PHP developers are based on their own needs of the voluntary development, it has a function must be practical use. Although it is not possible to say that PHP is stronger than similar products, its strength cannot be ignored.

2. PHP is a cross-platform product that runs on a variety of UNIX and Windows NT and has access to a variety of different databases, which is important to many people. Commercial products are often demanding and can only work with specific operating systems and databases. And people like to use their already familiar operating systems, Web servers, and databases, such as Linux, Apache, and MySQL.

3. PHP is open source software, many people do not agree, but they neglect the Web server market 58% of the Apache server, ignoring the Linux, FreeBSD and other open-source operating systems, these open source software together, The result is a very effective solution.

4. Even if the source code is not considered, PHP does not require any cost of the characteristics of commercial software can not be compared. Although ASP is also free, but many people ignore the cost of running Windows NT and MS SQL, and PHP and Linux/freebsd, Apache, MySQL cooperation with each other, almost no software costs, currently if piracy is not considered, How many people will insist on ASP?

5. PHP has a good technical support, can be emailed, forums, Web pages, IRC and other means to obtain technical support. That sounds funny, isn't it more effective than technical support for commercial software? In fact, in my personal experience with commercial software and open source software, this form of technical support is pretty good, imagine you can get technical services from the ASP development team? I think the more common result is that after a 800 phone call, it's just a bunch of useless advice, and finally you get bored with the phone. Even on-site service, it may be an engineer to re-install the system over and over again, until the system occasionally run normal, so that the system administrator at least can pretend that nothing to understand the appearance of a break. Open source allows you to come up with a phenomenon that is closer to the nature of the failure, not only for users who have experienced the same phenomenon, but also for PHP developers to help. What technical support is more effective than hundreds of thousands of users, most of whom are using PHP as a veteran, to provide help.

In any case, business support is not a necessary condition for a software epidemic, which in turn is correct, and recent examples of Linux have been commercially supported by popularity? For example, the latest version of the Web authoring Tool Dreamwaver 3.0, also began to support PHP markup, allowing direct PHP code in the writing. A growing number of domestic web developers are also beginning to gaze

http://www.bkjia.com/PHPjc/532430.html www.bkjia.com true http://www.bkjia.com/PHPjc/532430.html techarticle when building a website, most of the time not only need it to provide static Web access, but also want it to interact with browser users, access to the backend database to provide real-time more ...

  • Related Article

    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.