CoverYourASP --> Server Side Includes

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
19 active users
1401 visitors today
1239 pages today
(only part of today)
Tools I use

Copyright © 1999-2016 James Shaw.
All rights reserved.

RSS submissions

Now open source with SourceForge!

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...


<!--#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 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>' );


   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:


<%@ Language=JavaScript %>
// the first statement below enables buffering of the data sent to the browser.
//      see
// 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

// ============================================
// 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
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:


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 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


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


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


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


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


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 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


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


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


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


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


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


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


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


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


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

Featured sponsor
My favorite resources

I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...

Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?

New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!

See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!