13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

140 Chapter 5 Reusing Code <strong>and</strong> Writing Functions<br />

The require() statements in home.php load header.php <strong>and</strong> footer.php.<br />

As mentioned previously, the name given to these files does not affect how they are<br />

processed when you call them via require(). A common convention is to call the partial<br />

files that will end up included in other files something.inc (here, inc st<strong>and</strong>s for<br />

include).This is not recommended as a general strategy, as .inc files will not be interpreted<br />

as <strong>PHP</strong> code unless the web server has been configured specifically for this.<br />

If you’re going to do this, you should place your include files in a directory that can<br />

be seen by your scripts but does not permit your include files to be loaded individually<br />

via the web server—that is, outside the web document tree.This setup is a good strategy<br />

because it prevents these files from being loaded individually, which would either (a)<br />

probably produce some errors if the file extension is .php but contains only a partial<br />

page or script, or (b) allow people to read your source code if you have used another<br />

extension.<br />

The file header.php contains the CSS definitions that the page uses, the tables that<br />

display the company name, <strong>and</strong> navigation menus, as shown in Listing 5.3.<br />

Listing 5.3<br />

header.php—The Reusable Header for All TLA <strong>Web</strong> Pages<br />

<br />

<br />

TLA Consulting Pty Ltd<br />

<br />

h1 {color:white; font-size:24pt; text-align:center;<br />

font-family:arial,sans-serif}<br />

.menu {color:white; font-size:12pt; text-align:center;<br />

font-family:arial,sans-serif; font-weight:bold}<br />

td {background:black}<br />

p {color:black; font-size:12pt; text-align:justify;<br />

font-family:arial,sans-serif}<br />

p.foot {color:white; font-size:9pt; text-align:center;<br />

font-family:arial,sans-serif; font-weight:bold}<br />

a:link,a:visited,a:active {color:white}<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

TLA Consulting<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!