|CoverYourASP --> Server Side Includes
|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...
Please spread the word by recommending my site to your friends and colleagues!
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:
Config.aspThis 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.aspInit.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.aspThis 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.aspOutputs 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.aspThis 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.aspAll database access goes through this file. Connecting to the database, executing queries.
Further reading: Trapping connection errors, View the source
Email.aspTake 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.aspLogin.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.aspThis 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.aspUses 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.aspA 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.aspA 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.aspA 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.aspContains 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.aspThis 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.aspContains functions that deal with detecting browsers, and dealing with them differently.
Further reading: View the source
Format.aspA file containing functions to format common data types like currency and dates.