|
Simple Server Side Includes
By Scottie Claiborne (c) 2004
Successful-Sites.com
Anyone who's ever had to change a multitude of static pages on a site knows what a pain it is to find and change
the same snippets of code on one page after another- even using an Html editor's find-and-replace function can be
cumbersome since you have to upload all of the pages to the server again with the new code. Sometimes a page or two
will get missed or the find-and-replace function replaces some things you didn't intend to change, so it requires
some quality-checking time to run through all the pages and make sure the changes are there.
An easier way to manage pages in your site is by replacing chunks of repeating code, such as your navigation links,
with server side include (SSI) files. Instead of repeating the same code over and over, you create a separate file
with just that chunk of repeated code in it, then place a line of code on each page that tells the server to insert
the contents of a separate file into that spot on the page.
When someone visits your page, the server scans the code, pulls in the files needed to assemble that page and
returns the page as a single, complete page to the browser. Your "includes" code is replaced by the contents
of the file the code called. Since this all happens on the server's side of the transaction, your visitors don't
need to have any special browsers or plug-ins in order to make this work; SSI returns a "normal" html page
to the browser.
SSI files can simplify the maintenance of your site. Information that may change from time to time or that
replicates across many pages can be replaced with SSI files. Then, when you alter that include file, every page
on your website changes where the included file is being read. You will find include files often being used to
replace the entire header and footer for each page. When set up as includes, the background color, graphics,
navigation, or copyright information can be changed across the entire site by altering the include file for that
information. Without includes, you would be forced to go through all your pages to make the necessary changes.
You can use as many includes files on a page as you need- you can also call different includes files for different
pages. A good example is subnavigation links that only appear on certain pages, you only call that include file
where it's required. Any block of code in your site that repeats across pages is a good candidate for SSI.
The format for the code you will use to include a file within an Html page will depend on the operating system of
your server. For most sites, this will mean either Windows or Unix/Linux. If you are using Windows, you'll be
changing your file extensions to .asp. For Linux/Unix systems, you will use .php extensions. You should check with
your web host or server administrator if you are not sure what platform your site is hosted on.
Here are the two standard file include methods for both Windows and Linux systems (Note: you must use the
proper file extensions [.asp or .php] in order for these functions to work.) Remember, the included file will process
just as regular Html; all you are doing is splitting your pages into manageable parts for easy editing and
maintenance:
Windows (.asp)
<!--#INCLUDE FILE="header.asp"-->
1. Create a file called header.asp that only contains the code that you want to include.
2. Include the file with the above code in the place where the code should appear on each page.
3. Name all files with a .asp extension.
Linux/Unix (.php)
<? include("header.php"); ?>
1. Create a file called header.php that only contains the code that you want to include.
2. Include the file with the above code in the place where the code should appear on each page.
3. Name all files with a .php extension.
In both cases, relative paths can be determined as in HTML, such as:
<? include("../header.php"); ?>
or you can use an absolute (full) path, which is ideal for sites that have multiple levels of folders
in their structure:
<? include("http:www.site.com/header.php"); ?>
Changing the extensions of your pages can be a temporary headache, especially for established sites but in the
long run, the ease of maintaining and changing the site is worth the effort. Before changing page extensions, be
sure to have a custom 404 error page in place. (Most hosting packages today offer custom 404 page tools in their
control panels- contact your host if you don't see an option in your hosting control panel.)
SSI gives you the flexibility of a framed site without all the usability issues that come along with frames. It
allows you to separate the page content from the structure and graphics, giving you the freedom to easily change
any consistent element of the site without a major hassle. It's worth changing existing sites and should definitely
be considered when planning a new site.
About The Author
Scottie Claiborne is the owner of RightClickWebs.com and the facilitator
of the Successful Sites Newsletter. She is a speaker at the Search
Engine Strategies conferences and the High Rankings Seminars as well as the administrator of the High Rankings Forum.
|
|
|
|
|
Network Sites:
Cheap domain name registration :
Buy domain name with free domain hosting services.
Cheap domain registrar
offers domain name registration service with comprehensive free services.
Active-Venture.com provides cheap
web page hosting, web site hosting
and domain hosting service from $8.95.
|
|