Specifications
Implementing a templated structure such as this from a page design is very simple. In the
HTML source, you will find the <TD> where the main content cell begins. At this point, split
the HTML into two files; the first half becoming the header file and the second, the footer.
Whenever you display a page, show the header first, the page, and finally the footer.
Implementing the site with a header and footer template allows these template files to be easily
changed if the site design is updated.
PHP provides two configuration options that appear useful in this situation. The directives
auto_prepend_file and auto_append_file can be set on a per-directory basis to specify files
that are included before or after any script is processed.
However this has some limitations. If you had any scripts that produce no output and send a
redirect header such as
<? header(“Location: destination.php”); ?>
the header and footer files would still be displayed and the redirect would fail because output
has already been sent to the Web browser. This also causes problems with cookies and the
built-in PHP 4 session management functions because a cookie header will not function cor-
rectly after any output has been sent to the Web browser.
Image Manipulation
The writers who contribute stories will probably supply their own photographs to complement
the story. We want consistency, but what happens when one writer uploads a large, high quality
image and another writer uploads a small thumbnail?
Assuming that the pictures in question are primarily photographs, we can insist on JPEG
images only, and take advantage of functions in PHP to manipulate the images. This topic is
covered in detail in Chapter 19, “Generating Images.”
We have created a simple script called resize_image.php that will resize an image on-the-fly
so that it can be displayed with an <IMG SRC> tag. This script is shown in Listing 26.1.
LISTING 26.1 resize_image.php Resizes a JPEG Image On-the-Fly
<?
if (!$max_width)
$max_width = 150;
if (!$max_height)
$max_height = 100;
$size = GetImageSize($image);
$width = $size[0];
Building a Content Management System
C
HAPTER 26
26
CONTENT
MANAGEMENT
SYSTEMS
593
32 7842 ch26 3/6/01 3:36 PM Page 593










