PHP: Static vs. Dynamic Websites

Introduction | Static vs. Dynamic Websites | Using PHP on RCI or Eden | A Simple PHP Program | Practice 1 | Loops | Practice 2 | Functions | Practice 3 | Conditionals | Practice 4 | PHP and Online Forms | Practice 5 | PHP and E-mail | Practice 6 | Conclusion

A website is collection of documents written in the HTML language. When a user looks at a website with a browser (e.g. Netscape), the browser is able to follow the instructions presented to it in HTML to make a website look a certain way. Click Here to open a new browser window which will show you an average website. If you were to look at the HTML code for this site, you would see the following:

<title>An Average Website</title>
<body bgcolor="#003399" text="#ffcc33">
<h1>An Average Website</h1>
<p>This is an average website.  

The above HTML code for "the average website" is static. That is, if the user were to reload a static website, they would see the exact same content every time. Its content was written directly by an author, and when the user goes to the site, that code is downloaded into a browser and interpreted.

In contrast to a static website, a dynamic website is one whose content is regenerated every time a user visits or reloads the site. Click Here to open a new browser window to a dynamic page which tells the time at the particular second that it was accessed. If you click on the "Reload" button several times, you should notice that the time will change.

There are a variety of languages available to make a dynamic website but in this course, we will focus on PHP. PHP stands for PHP: Hypertext Preprocessor. This confuses many people because the first word of the acronym is the acronym. This type of acronym is called a recursive acronym. The curious can visit Free On-Line Dictionary of Computing for more information on recursive acronyms.

An advantage of PHP (besides that it is available at no cost AND that it is Free Software so you have the Freedom to run, copy, distribute, study, change and improve it) is that it offers cross-platform compatibility. In other words, it will not matter what platform (Microsoft Windows, Machintosh, or a version of Unix) your users are running, since there is no need for any additional software in order to see PHP's dynamic content. This is because the dynamic content is processed on the server side, and then sent as if it were static.

When you create a static web page, you simply write HTML code. Writing a dynamic page with PHP is similar, except you embed the PHP code inside of the HTML code. For this reason PHP is called an HTML-embedded scripting language. For example, consider the PHP code for the above time-telling page:

<h3>The Date & Time: </h3>
  <? echo (date ("l dS of F Y h:i:s A")); ?>

Note: Don't worry if you do not understand all of the details of the PHP code above. It is just an example to demonstrate how PHP is embedded in HTML. All you need to know for now is that PHP can retrieve the time and date and display it dynamically on a webpage.

Notice that in the above example the PHP is distinguished from the HTML with the symbols   <?   (less-than followed by a question mark)   and   ?>   (a question mark followed by a greater-than). The symbol combination   <?   opens up a PHP statement, and tells the webserver that all statements that follow until the symbol combination   ?>   are PHP statements. You can also have the sequence "php" after your first question mark (<?php). The following syntaxes are both valid ways to indicate a PHP code block:

<?    ...   ?>
<?php ...   ?>

For this tutorial we will use the first of the above examples (<? ... ?>), but you should be aware of alternate syntaxes, since this tutorial will encourage you to go to the main PHP website ( to examine supplementary code written by others, who might use the second standard.

There are many ways to indicate the boundarys of an HTML embeded scripting language. ASP uses <% by default. If you are concerned about ambiguity (this is espcially important on web servers that run more than one HTML embeded scripting language), you should probably use this syntax:

<?php ...   ?>

PHP runs on the server side, which means that the webserver that sends an HTML file to a user's browser, will carry out the instructions found in the embedded PHP code first, and then send the output of the PHP code along with the HTML code. The result is a webpage with dynamic content.

To demonstrate this idea, look at the Date & Time example again, and use your browser's "view source code option" to view the source code for the above page, and compare what you see to the above code. Instead of seeing the PHP code that you see between   <?   and   ?>   above, you see the actual time, or in other words, the output of the PHP code that you see above. This is because the web server replaces the PHP code with the content that the code was written to produce.

Previous Page Next Page