You are viewing a plain-jane printable version of http://CoverYourASP.com/ssi.asp.
See how this was done

 

SSI allows me to suck in common code from files into my pages. You'll see in the examples below how I have a common Init () function to output the common HTML <head>, a common Header () function to output the same header at the top of each page, and a common Footer () to output the same bottom of page.

I use the same template for each page, as shown below. This is literally my source code, and the file I use when I create any new page on the site. I load this, then start typing in the new code...

Did you know you can download all the source code (and the database) of this site? Then get my newsletter to be emailed when I update the source code!

Please spread the word by recommending my site to your friends and colleagues!

This is JScript (server-side JavaScript), not the more common VBScript. More...

Blank.asp

<!--#include file = "/include/Startup.html"-->

<%
// ============================================
// NOTE: all source code downloaded from CoverYourASP was written by
// James Shaw (unless stated otherwise), and is copyright (c) 2000-2002
// by James Shaw. You can use the code for any purpose, but do not
// publish or distribute the content in any way.
//
// See http://CoverYourASP.com/Legal.asp for up-to-date details.
// ============================================

// increment the parent articles counter
// sIncArticlePage = '';

// output relevant meta tags
Init( "not implemented" );

// output common top of page
Header( 'not implemented' );

// output page content
Content ( );

// output common bottom of page
Footer( );

// ============================================
// the content of this page - every page has a function 'Content' that
// is called above.
// ============================================
function Content ( )
{
   Out ( '<td valign="top" class="content">' );

      Out ( 'This page not yet implemented.' );

//      Out ( '<p align="right"><a href="">Part 2: ...</a>' );

      ShowBottomBanner()

   Out ( '</td>' );
   Out ( '<td background="images/gx/navgap.gif" valign="top">' );

      // show rotating banners
      ShowBanners ( 1 );

   Out ( '</td>' );
}
%>

The syntax of the include should be familiar to any C/C++ programmers, except for the "file" part. You can use "file" or "virtual". Use the file keyword to indicate a relative path, and the virtual keyword to indicate an absolute path beginning with a virtual directory.

Note: Regardless of Microsoft's recommendations to use an .inc extension for include files, DON'T DO IT. Anyone can view the contents of these files if they know the name, and you could "give away" potentially fatal information. The golden rule is: Always use an .asp extension.

The effect of this #include line, of course, is to suck in the contents of the referenced file as if it was there all along!

First, let's look at the Startup.asp file that contains all the standard page elements:

include/Startup.asp

<%@ Language=JavaScript %>
<%
// the first statement below enables buffering of the data sent to the browser.
//
//      see http://learnasp.com/learn/whybuffer.asp
//
// the second stops the page being held in a cache - database driven pages
// will be out of date, and page counters won't always be called otherwise
%>
<%
Response.Buffer=true;
Response.Expires=0;
%>

<%
// ============================================
// standard page elements to all pages
// ============================================
%>
<!--#include file = "/include/Config.html"-->

<!--#include file = "/utils/Init.html"-->
<!--#include file = "/utils/Header.html"-->
<!--#include file = "/utils/Footer.html"-->
<!--#include file = "/utils/Banners.html"-->
<!--#include file = "/utils/Browser.html"-->
<!--#include file = "/utils/Database.html"-->
<!--#include file = "/utils/Email.html"-->
<!--#include file = "/utils/Format.html"-->
<!--#include file = "/utils/Login.html"-->
<%
// ============================================
// commonly used global variables
// ============================================
var undefined;         // undefined!

// set this to update a different pages hit counter
var sIncArticlePage;

// this is set if you use the magic word
var bValidUser = false;

// set if you're running on real CYA server
var bRunningOnCYA = false;

// was the user redirected here from ShawThing.com?
var bReferred = false;

// should we allow spiders to index/follow from this page?
var bAllowIndex = true;

// pass on the magic word to other pages
var sMagicWord = '';

// get some server variables for common use
var sServer;
var sAgent;

// to restrict dynamic content when running a frozen template
var bNoDynamic = false;

// to display a plain-jane page for printing
var bPlainJane = false;
%>

In the file above I've first set my script language to JavaScript, turn buffering on to improve performance (Response.Buffer=true) and make sure pages aren't cached (Response.Expires=0). I then include the utils\ files that contain the standard page elements. Here's a brief description of the files:

Config.asp

This file contains settings that control the functioning of the web site. You can specify how to connect to your database, the type of email system you have, passwords and more.
Further reading: Configuring the download

Init.asp

Init.asp initializes the page, including performing once-a-day tasks, redirecting spiders to special pages, outputting the HTML <HEAD> and relevant META tags and incrementing the article counter in the database.
Further reading: Setting the <BASE HREF>, Changing the META tags, Hiding debug information on your pages, Counting the hits to the articles, Storing banners in Application variables, Performing once-a-day operations, Simple password protection, The BrandNewDay( ) function, View the source

Header.asp

This file outputs the header at the top of every page on the site. That's the beauty of SSI - change this one file and every page gets the new header automatically.
Further reading: Counting visits and page views, Signing in members, Resizing pages to fit screen, View the source

Footer.asp

Outputs the simple footer at the bottom of all my pages, and contains code to log information about visitors to my site.
Further reading: Storing statistics about my readers, How many visitors are leaving your pages early?, View the source

Banners.asp

This file handles all banner-related functions. Displaying advertising banners at the top of the pages and information banners at the side.
Further reading: Serving the Ads, Rotating banners, View the source

Database.asp

All database access goes through this file. Connecting to the database, executing queries.
Further reading: Trapping connection errors, View the source

Email.asp

Take a wild guess! All emails get sent through functions in this file, and email addresses get validated here. CDONTS, ASPEmail, ASPMail and JMail are currently supported, and others can be supported if you ask!
Further reading: Getting feedback email from a form, Live email validation, View the source

Login.asp

Login.asp has all the membership functionality in it. Login/logout, registering new users, storing data in cookies, membership levels, etc.
Further reading: The membership system, View the source

Personalize.asp

This contains all the functions needed to display personalized content on the front page - the introduction, what's new, what's popular, categories, etc
Further reading: Personalizing the front page, View the source

ShowFile.asp

Uses the FileSystemObject to open files and display them. Uses regular expressions to convert HTML so it can be displayed rather than interpreted by your browser.
Further reading: Viewing the source code, View the source

Survey.asp

A function to display surveys from a database, collate the answers and display the results in simple bar charts.
Further reading: Surveying your readers, Design my search function, View the source

Search.asp

A function to display a search form, turn the search expression into a SQL statement, execute the statement and display the results!
Further reading: Adding Search capability, Design my search function, View the source

WalkFolders.asp

A simple function to walk through your folders and sub-folders, passing back the folder and file names for processing.
Further reading: Walking through the file system, View the source

Newsletter.asp

Contains functions that allow you to add and remove names from the newsletter mailing list.
Further reading: Subscribing to the mailing list, Sending out the newsletter, View the source

News.asp

This is a trick! This file contains just one function that contains hard-coded news items. So how is that dynamic? A simple component I wrote writes a new version of this file twice a day!
Further reading: Using HTTP and FTP to get the ASPWire news feed., View the source

Browser.asp

Contains functions that deal with detecting browsers, and dealing with them differently.
Further reading: View the source

Format.asp

A file containing functions to format common data types like currency and dates.
Further reading: Formatting with JavaScript, View the source