The purpose of this assignment is to give you the chance to practice some of the techniques made possible by PHP file inclusion. These techniques are demonstrated in the CSC 107 web site.
You may create a new web site from scratch for this assignment, or you may begin with an HTML site you have previously created and convert it to PHP. Note that whether you choose to start from scratch or to convert an existing web site, the design should be such that individual pages share consistent content elements (such as a navbar, title area, footer, etc.) so that you can fulfill the requirements of this assignment. For top credit, your site should be organized hierarchically, with at least one file in a folder below the level of the root home page. This organization should not be arbitrary; rather it should make sense given the content of your site. For example, in the CSC 107 web site, the labs and assignments each have their own separate folders, to keep them separate from the general course material.
Eliminating Redundancy
The first goal of the assignment will be to eliminate unnecessary redundancy. If you have chosen a web site design as described above, each page of the site will have to include their own copies of the site-consistent content. This makes maintenance difficult: in case you want to update or change any of this content, you would have to change it in each and every single file.
Centralize as much of the redundant content material as you can into one or more PHP files that can be included by all the pages in your site. For example, the CSC 107 web site uses a single file to produce all the HTML header material, including another separate file for the navigation links. As is typical, although the basic header content is nearly identical, a few details change. For example, the link to the style sheet file differs for pages that are not at the home page root level. Also the page title and headers change. In order to deal with these sorts of changes, you will probably need to introduce some variables. Set their values before including the header or common-content file, and in those files use the variable values to customize the content generated. For example, you will probably want to have a variable that holds the path to the web page root, and you will refer to this variable when you generate the <link> tag to the CSS file.
So your regular page in a subfolder would hold something like this:
<?php $root = ".."; include("$root/common.php"); ?>
Your common content page at the root would hold something like this:
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$root/csc107.css\" />"
Note the escape codes for double quotes within the quoted string above: \".
Orienting the User
Just for fun, you should try another application of PHP includes. This one is also visible in the CSC 107 home page: in the lower half of the colored stripe on every page is a navigation aid that shows the current page within a hierarchy of pages at increasing levels of the site. This is intended to help the user see how a particular page fits into the web site as a whole.
Again, these links could be simply written into every page. But if a particular folder were moved around, as can often happen in a big corporate web site, those links would all have to be rewritten. Better to have them automatically generated using PHP includes.
The secret: each page includes a file with some consistent name, say loc.php, within the same folder. That file in turn includes the same file in the parent folder ../loc.php, and so on up to the home page root. Each included file generates enough HTML content to display its part of the context string. So for example on the CSC 107 page the root file creates the links to Smith College, the CS Department, and the CSC 107 home page. The lab and assignment folders have their own version which adds the link to their folder indices. Finally, the individual content pages add their own description at the end.
One note about this structure: because it leads to the inclusion of many small files before an individual page can be served, this setup may not be suitable for all applications -- particularly those expecting heavy use that require a rapid response time.