123Webmaster.com : Onsite : Building
How to Build a Database Driven Site Using SSI

by Corbbmacc O'Connor

If you have ever tried to build a database driven site with other programming languages like PHP and Cold Fusion, you know how difficult it can be. This is a very powerful, yet very simple way to build a database driven site.

Before we begin, you need to make sure that your server supports Server Side Includes. If not, then this method of making a database driven site will not work. Before you go any further, e-mail the support staff of your web hosting company and ask them.

Are you ready? Let's begin!

First create a new HTML document. Create the page like you normally would using regular HTML tags. Where you want your content to be, insert the following tags.

<!--#set var="which" value="$QUERY_STRING_UNESCAPED" -->
<!--#if expr="$which != ''" -->
<!--#include virtual="/content/$which" -->
<!--#else -->
<!--#include virtual="/content/error.txt" -->
<!--#endif -->

Save the file as display.shtml and minimize it for now. Now create a new directory on your hard drive where all of your other web site files are. This is the folder where all of your content files will be stored. I usually name mine content.

Now open up the file that you saved a little bit ago. Remember the text in red? That is the folder that you just created. Make sure that the two folder names match. Also make sure that you do not have http://whatever.com before it. It is crucial that this not be there. Otherwise, the entire database can get messed up.

Minimize all of the files that are currently open. Open up Notepad (Windows) or SimpleText (Macintosh). This is how all of your database files will be created. In the file, type what you want to be displayed in place of all those commands that were in the display.shtml file. You can use HTML, JavaScript, and any other programming language in these files. The first file that you will create is an error file. This file will be displayed when the file that the user wants does not exist. Type the following:

The file that you are looking for does not exist. Please report this broken link to us by e-mailing us.

You can change this if you would like. Even if you don't change the above file, make sure to change your e-mail address. Save this file in your content directory and call it error.txt.
Open up the first file you created display.html. Remember the text in blue? That is the path (not URL) to the error file that you just created. Make sure that the path is correct and that it points to the file we just created.

Now upload everything to your web site.

Continue to create more files using Notepad or SimpleText.

To access the database, type the following in the address bar of your web browser: http://www.yourdomain.com/display.html?filename.txt. The text in blue is the name of the file that you want displayed. You can create links to this database easily! Just create a link as usual, but make sure to include the entire URL including the question mark and the text after it.

Good luck with your new database!

Discussion - Server Side Scripting
Related Sites - Corbbmacc O'Connor is the webmaster of a webmaster information site entitled Just for Webmasters. Corbbmacc is the editor of a FREE weekly newsletter called The Guilded Webmaster.The Guided Webmaster is packed full of up-to-date information for webmasters. For more information or to sign up, visit: http://www.justforwebmasters.com/newsletter/.