PHP DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


PHP Foundations

An Introduction to PHP

02/22/2001

What exactly is PHP anyway?

PHP is short for what is officially called "PHP: Hypertext Preprocessor." PHP was created by Rasmus Lerdorf, a developer who needed a tool to keep track of who was looking at his resume. The first version of Lerdorf's preprocessor (known then as PHP/FI) was released in 1994. Since then, PHP has become popular in the open-source community and was renamed PHP with the release of version 3.0. PHP is now at version 4.0 and is used by over 3 million web sites on the Internet.

PHP represents a robust open-source development language that provides the tools and flexibility to accomplish virtually any task. PHP is an embedded language which means developers can jump between raw HTML code and PHP without sacrificing readability. Beyond its basic syntax, PHP also boasts a wide range of interfaces allowing it to communicate with everything from other web pages, to databases including ODBC, and other programming languages such as Java or COM.

So what can it do?

At a fundamental level, PHP has all of the features of a complete programming language (control structures, repetitive tasks, and variables) but perhaps one of its most powerful features is database access. With PHP it is possible to access over 19 different types of databases and manipulate data within those databases based on input from the user via a web page. You can also send e-mail, work with newsgroups, and actually open a connection to another web site -- and get or send data with it. If you are already familiar with ASP development, PHP can also communicate with other server-side languages such as Java and use COM interfaces.

Do you have a guestbook on your web site? Do you subscribe to a third-party service that provides statistics on site visitors? Would you like to know how a user got into your web page (the specific page), where they visited on your web site, and what page they left from? With PHP, such tasks are almost trivial. PHP provides the means to do everything from processing data to generating graphics on the fly.

How does it work?

For those of you who are familiar with web development, the term CGI (Common Gateway Interface) may be familiar to you. CGI provides a way for developers to write computer programs that can construct HTML and process data from web pages dynamically. Before CGI, web developers were forced to write static HTML pages that required tedious manual updates.

PHP is a customized, embedded CGI language. Because PHP is server-side technology, the person viewing the web page needs no special programs or browser plug-ins for PHP to work. PHP is compatible with all major web browsers, and although it is classified as a CGI, PHP is a tool that provides much more power. It allows a web developer to dynamically construct a web page based on data gathered from a third source (a database or otherwise) and then communicate that data through almost any means provided by the Internet. The real benefit of this is the developer can do these things with little or no knowledge of the inner workings between the CGI and the database they are communicating with.

As mentioned before PHP is a hypertext preprocessor. In a less technical sense, this means that when a user points a browser at your web site, PHP gets a chance to make "last-minute" changes to the page before the user sees it (See Figure 1).

Web request processing with and without PHP.
Figure 1. Web request processing with and without PHP.

A web server with PHP installed takes the extra step of allowing PHP to process the requested document before displaying it to the user. From this extra step PHP can then perform any operation including access the database, send e-mail messages, or open a connection to another Internet service (such as another web server). All professional web sites including search engines and web-based e-mail services use this technology model where the server has an intermediate-processing step between the actual document and the user -- without this model those sites could not exist.

How do I begin using PHP?

To use PHP (or any other server-side web scripting language), it must be installed on your web server. PHP's parser comes in two flavors -- a CGI executable and a module for the Apache web server. If you do not own your own web server, a list of PHP-enabled web hosts is available from php.net. If you are a web-hosting provider, or have access to your own web server, download PHP from the official PHP site along with complete installation documentation.

Note: To take full advantage of all of PHP's functionality, other freeware third-party software may also need to be installed. Consult the PHP documentation for more information on PHP functions and where to find the appropriate third-party software.

I have PHP installed, how do I use it?

If you already have PHP installed but want to know how to program in PHP there are many tutorials available. The best place to start learning PHP is from this web site or the PHP homepage.

John Coggeshall is a a PHP consultant and author who started losing sleep over PHP around five years ago.


Read more PHP Foundations columns.

Discuss this article in the O'Reilly Network PHP Forum.

Return to the PHP DevCenter.

 




Valuable Online Certification Training

Online Certification for Your Career
Earn a Certificate for Professional Development from the University of Illinois Office of Continuing Education upon completion of each online certificate program.

PHP/SQL Programming Certificate — The PHP/SQL Programming Certificate series is comprised of four courses covering beginning to advanced PHP programming, beginning to advanced database programming using the SQL language, database theory, and integrated Web 2.0 programming using PHP and SQL on the Unix/Linux mySQL platform.

Enroll today!


Sponsored by: