Specifications

You can see in Listing 5.1 that a number of distinct sections of code exist in this file. The
HTML head contains Cascading Style Sheet (CSS) definitions used by the page. The section
labeled page header displays the company name and logo, menu bar creates the pages
navigation bar, and page content is text unique to this page. Below that is the page footer. We
can usefully split this file and name the parts header.inc, home.php, and footer.inc. Both
header.inc and footer.inc contain code that will be reused on other pages.
The file home.php is a replacement for home.html, and contains the unique page content and
two require() statements as shown in Listing 5.2.
LISTING 5.2 home.phpThe PHP That Produces TLAs Homepage
<?
require(“header.inc”);
?>
<!-- page content -->
<p>Welcome to the home of TLA Consulting.
Please take some time to get to know us.</p>
<p>We specialize in serving your business needs
and hope to hear from you soon.</p>
<?
require(“footer.inc”);
?>
The require() statements in home.php load header.inc and footer.inc.
As mentioned, the name given to these files does not affect how they are processed when we
call them via require(). A common, but entirely optional, convention is to call the partial files
that will end up included in other files something.inc (here inc stands for include). It is also
common, and a good idea, to place your include files in a directory that can be seen by your
scripts, but does not permit your include files to be loaded individually via the Web server.
This will prevent these files from being loaded individually which will either a) probably pro-
duce some errors if the file extension is .php but contains only a partial page or script, or
b) allow people to read your source code if you have used another extension.
The file header.inc contains the CSS definitions that the page uses, the tables that display the
company name and navigation menus as shown in Listing 5.3.
The file footer.inc contains the table that displays the footer at the bottom of each page. This
file is shown in Listing 5.4.
Using PHP
P
ART I
124
07 7842 CH05 3/6/01 3:35 PM Page 124