Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Development and Maintenance

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Server Side Includes; The Basics

Server Side Includes, also known as "SSI" can be a very useful web building tool:

  • Keep multiple pages updated with a change on only one file. Use one central file for any code you may want to repeat from page to page.

  • Display the output of CGI programs: live news/weather information retrieved from remote sites, your current "latest news", a count of members, the visitor's IP address, the last page the surfer visited if s/he arrived via a link -- pretty much anything a CGI program can do.

It is referred to as "Server Side" because SSI is taken care of at the server (rather than at the browser) level. As the server is sending your page to your visitor's browser, it scans your page for special tags that tell it what you want included in those spots. Whenever it finds such a spot, the server includes what you want.

"Includes" because SSI includes stuff on your page, at the spot you tell it to.

Wherever you have the same code on many pages (such as navigation bars, subscription forms, bottom-of-page links), use SSI and you'll only need to change one file to change every page that it's used on.

Wherever you need freshly updated information every time a page loads, use SSI.

It's simple.

So why isn't everybody using it? Because it takes a few nanoseconds of time for the server to scan the page and include the material. And because not everybody knows how to use the tags.

Most hosting companies allow their accounts to use SSI. A common requirement is the .shtml file extension for SSI pages. This is because it does take a tiny bit of time and server resources to scan the page and include material. It is assumed that you'll only use the .shtml extension for SSI pages and use .html and .htm for the others.

If you don't know whether or not you can use SSI on your server, do a test.

Make two files. Name the first file mytest.shtml and the second file myssi.txt

The content of the mytest.shtml is:

<html><body>It goes here.
<!--#include file="myssi.txt"-->
</body></html>

The content of the myssi.txt is:

<font size="+2">
<b>Here I am!</b>
</font>

Upload those two files to your server and put the URL of mytest.html into your browser. If you see the words "It goes here. Here I am!", then you can use SSI on your server.

Notice how the SSI tag is within HTML comment tags. Some servers will work with a space after the "<!--" comment-begin characters or a space before the -->" comment-end characters. But some servers will produce an error message when you do that. Example:

<!-- #include _________ -->

might work on some servers, but not on all. To be certain, do it like this:

<!--#include _________-->

Here is some of what you can do with SSI:

  1. The tag: <!--#include file="__________"-->

    Replace the underscore with the file name you want included. The file name can just about anything you want (.txt and .html file extensions are common), but it must be text. It can be plain text, HTML code, JavaScript, and anything else composed of text. However, do not use binary files such as images or sound files.

    The file you include can have HTML code for images and sound files, but you just can't put the image/sound file name directly into the SSI tag itself.

    The file must reside in the same directory as your .shtml page.

  2. The tag: <!--#include virtual="__________"-->

    Same as file="__________" except your include file may be in different directory. The file name, in this case, is a virtual file name.

    Examples:

    "../filename.txt" specifies a file one directory lower.

    "nextdir/filename.txt" specifies a file in the nextdir directory from where your .shtml file is at.

  3. The tag: <!--#exec cgi="__________"-->

    Replace the underscore with the CGI program's file name. The file name may be a virtual file name, but it cannot be a http://... URL.

    The CGI program must return text, but that text can be JavaScript or HTML tags for images and/or sounds or anything else that browsers understand.

With those three simple SSI tags, you can have one central file for any code you may want to repeat from page to page.

Will Bontrager

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC