PHP is a programming language that's used mostly for building web sites. Instead of a PHP program running on a desktop computer for the use of one person, it typically runs on a web server and is accessed by lots of people using web browsers on their own computers. This section explains how PHP fits into the interaction between a web browser and a web server.
When you sit down at your computer and pull up a web page using a browser such as Internet Explorer or Mozilla, you cause a little conversation to happen over the Internet between your computer and another computer. This conversation and how it makes a web page appear on your screen is illustrated in Figure 1-1.
When you sit down at your computer and pull up a web page using a browser such as Internet Explorer or Mozilla, you cause a little conversation to happen over the Internet between your computer and another computer. This conversation and how it makes a web page appear on your screen is illustrated in Figure 1-1.
Here's what's happening in the numbered steps of the
diagram:
-
You type www.example.com/catalog.html into the location bar of Internet Explorer.
-
Internet Explorer sends a message over the Internet to the computer named www.example.com asking for the /catalog.html page.
-
Apache, a program running on the www.example.com computer, gets the message and reads the catalog.html file from the disk drive.
-
Apache sends the contents of the file back to your computer over the Internet as a response to Internet Explorer's request.
-
Internet Explorer displays the page on the screen, following the instructions of the HTML tags in the page.
Every time a browser asks for http://www.example.com/catalog.html, the web server
sends back the contents of the same catalog.html
file. The only time the response from the web server changes is if someone edits
the file on the server.
Here's what's happening in the numbered steps of the
PHP-enabled conversation:
-
You type www.example.com/catalog/yak.php into the location bar of Internet Explorer.
-
Internet Explorer sends a message over the Internet to the computer named www.example.com asking for the /catalog/yak.php page.
-
Apache, a program running on the www.example.com computer, gets the message and asks the PHP interpreter, another program running on the www.example.com computer, "What does /catalog/yak.php look like?"
-
The PHP interpreter reads the file /usr/local/www/catalog/yak.php from the disk drive.
-
The PHP interpreter runs the commands in yak.php, possibly exchanging data with a database program such as MySQL.
-
The PHP interpreter takes the yak.php program output and sends it back to Apache as an answer to "What does /catalog/yak.php look like?"
-
Apache sends the page contents it got from the PHP interpreter back to your computer over the Internet in response to Internet Explorer's request.
-
Internet Explorer displays the page on the screen, following the instructions of the HTML tags in the page.
PHP is called a server-side
language because, as Figure
1-2 illustrates, it runs on a web server. Languages and technologies such as
JavaScript and Flash, in contrast, are called client-side because they run on a web client (like a
desktop PC). The instructions in a PHP program cause the PHP interpreter on a
web server to output a web page. The instructions in a JavaScript program cause
Internet Explorer, while running on your desktop PC, to do something such as pop
up a new window. Once the web server has sent the generated web page to the
client (Step 7 in the Figure
1-2), PHP is out of the picture. If the page content contains some
JavaScript, then that JavaScript runs on the client but is totally disconnected
from the PHP program that generated the page.
No comments:
Post a Comment