By the end of this lesson, you should:
Recall that Snoutbook is Facebook for dogs. It has the tree, equivalent to Facebook’s wall. When Ivan posts to his tree, everyone can see his new entry.
Figure 1. Ivan’s tree
If Mazie wants to look at Ivan’s tree, she points her browser at
tree.php has PHP code embedded into HTML.
Here’s what happens when Mazie looks at Ivan’s tree.
Figure 3. Snoutbook’s architecture
The browser asks the server for
tree.php (1). The Web server – Apache, say – loads the file
tree.php from disk into memory (2). The Web server sees that the file’s extension is
.php, and sends the file to the PHP interpreter (3).
The PHP interpreter is a program, running on the same computer as Apache. It knows how to follow instructions written in the PHP language. These PHP instructions are written by a person – human, dog, or some other intelligent being.
So the PHP interpreter runs the PHP code in
tree.php (4). This code asks the database server for Ivan’s tree postings. The database server returns the data. The PHP code wraps the data in HTML tags, like
When it has finished running all the code, the PHP interpreter sends the result back to the Web server (5). The result will be a bunch of HTML, created by the PHP code in
tree.php. The server then sends the data to the browser (6).
The browser just gets HTML. It doesn’t know, or care, that it was generated by a program.
So that’s what PHP does. PHP code runs on a server, and generates HTML (usually – it can output other types of data as well).
PHP code can work with a database server. But it can do other things as well.
When you can write PHP code, you can do, well, all sorts of things.
PHP programs run on Web servers. They can work with database servers. PHP can also send email, read and write files, and interact with many kinds of other servers.
Let’s look at the tools you’ll need to make your PHP work easier.