Requesting Data from a Web Page






Requesting Data from a Web Page

How all of these pieces integrate together can be tricky to understand. If a web server detects PHP code, it determines whether the file is a PHP file, and if so, turn over the processing of the page to the PHP interpreter without any additional participation by the web browser. But if you include an external CSS file, your browser issues a separate request for that file before viewing the page.

PHP Interpretation on the Server

This processing of the PHP on the server is called server-side processing. When you request a web page, you trigger a whole chain of events. Figure illustrates this interaction between your computer and the web server (host of the web site).

While the user only types in a URL and hits Enter, there are several steps that occur behind the scenes to handle that request


Here's the breakdown of Figure:

  1. You enter a web page address in your browser's location bar.

  2. Your browser breaks apart that address and sends the name of the page to the web server. For example, http://www.phone.com/directory.html would request the page directory.html from www.phone.com.

  3. A program on the web server, called the web server process, takes the request for directory.html and looks for this specific file.

  4. The web server reads the directory.html file from the web server's hard drive.

  5. The web server returns the contents of directory.html to your browser.

  6. Your web browser uses the HTML markup that was returned from the web server to build the rendition of the web page on your computer screen.

The HTML file called directory.html (requested in Figure) is called a static web page. It is static because everyone who requests the directory.html page gets exactly the same page.

For the web server to customize the returned page, PHP and MySQL are added to the mix. Figure illustrates the extra steps that occur in the chain of events on the web host.

The PHP interpreter, MySQL, and the web server cooperate to return the page


Each step in the chain is listed here:

  1. You enter a web page address in your browser's location bar.

  2. Your browser breaks apart that address and sends the name of the page to the host. For example, http://www.phone.com/login.php requests the page login.php from www.phone.com.

  3. The web server process on the host receives the request for login.php.

  4. The web server reads the login.php file from the host's hard drive.

  5. The web server detects that the PHP file isn't just a plain HTML file, so it asks another processthe PHP interpreterto process the file.

  6. The PHP interpreter executes the PHP code that it finds in the text it received from the web server process. Included in that code are calls to the MySQL database.

  7. PHP asks the MySQL database process to execute the database calls.

  8. The MySQL database process returns the results of the database query.

  9. The PHP interpreter completes execution of the PHP code with the data from the database and returns the results to the web server process.

  10. The web server returns the results in the form of HTML text to your browser.

  11. Your web browser uses the returned HTML text to build the web page on your screen.

This may seem like a lot of steps, but all of this processing happens automatically every time a web page with PHP code is requested.

When developing dynamic web pages, you work with a variety of variables and server components, which are all important to having an attractive, easy to navigate, and maintainable web site. Next, it's time to install the three major cogs needed to make this work: Apache, PHP, and MySQL.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows