Modular Design
An important factor to consider when designing a family of websites for your Internet business, is the ease of maintenance. You should always make your websites modular, so that you can make across-site changes by changing one file.
What is the best way to do that? Break the page down into sections, and put each in a separate file. You can use SSI includes, or PHP. If you don’t know PHP you really don’t need to learn much about it to use this technique. In fact, I’ll explain it all here.
This assumes you are using a hosting service that includes PHP, which they almost all do automatically. Now, if you want to use the .htm or .html suffix for your web pages, you need to have SSI turned on so you can use includes:
<!–#include virtual=”myfile.php” –>
Or you can add one line to your .htaccess file if you are using a Linux server:
AddType application/x-httpd-php .htm .html
Or you can just name your file with a .php extension, and then your includes will work without any further modification.
Now, suppose one section of your page that repeats is the footer. You put the footer HTML code in a file and save it as footer.php — then you can include it with:
<?php include(”footer.php”);?>
Or, if you have SSI turned on:
<!–#include virtual=”footer.php” –>
Either way, you will need to include the relative path if the file is not in the same directory as your HTML page.
Things get a little more complicated when you want to put the header section of your page in its own module. The header usually includes your keywords, page title, and other meta tags that change from page to page. There are two solutions to this problem.
The easiest approach is to put the variables in a database, then look up their values in the include file, and assign them to variables. Variable can be inserted in your HTML just like the include file itself was:
<title><?php echo($title);?></title>
A less satisfactory solution is to have a variable assignment file for each HTML file, that initializes those values that change from page to page. Changing these is just as much trouble as changing each HTML file on its own — but if you want to change other parts of your header, you still benefit from having separate modules. You can have the include file detect the correct variable file by giving it the same name as the HTML page it applies to, but with a different suffix. So you might use .inc files, for example. This bit of PHP code included in your header.php file will find the correct .inc file to match the .htm or .php file it is included in (assuming .htm as the suffix on the main HTML file):
<?php
$file=basename($_SERVER[’PHP_SELF’],’.htm’);
include($file.’.inc’);
?>
If you put the main content for your page in another include file, and use a consistent prefix and suffix, the same method will find the correct file, so long as it is in the same directory as the main HTML file:
<?php
$file=basename($_SERVER[’PHP_SELF’],’.htm’);
include(’x’.$file.’.php’);
?>
You can use anything you like in place of ‘x’.
To avoid getting annoying error messages that might reveal details of your page structure to hackers, your initial header file should include this code to turn off PHP errors:
<?php error_reporting(0);?>
That the number 0, not the letter O inside the parenthesis. When trouble-shooting your pages, looking for problems, you will want to replace the above line with:
<?php error_reporting(E_ALL);?>
Whatever scheme you use to modularize your websites, be consistent from one site to the next, and you will find it much easier to maintain your Web Empire. Being consistent in method does NOT mean having the same page design elements, links, file structure, etc., for your Internet business sites, as we will see in our next post on the hitherto unmentioned Duplicate Layout Penalty.