Pardon my language, but that's the exact phrase many people use when asked of this question. Allow me to explain. SSI stands for Server Side Includes, and are HTML commands that work like macros. Uh? In English, it means the use of the server to dynamically include something into a document. SSI is server-dependent, and is supported even by NS 2 (in other words, virtually all browsers on the net).
SSI works like this- You include inside your document a code fragment that looks something like this:
<!--#include file="afile.htm" -->
Servers that support SSI will not merely read the above as a HTML comment, but as a command that informs the server to insert "afile.htm" at that location of the document. The biggest difference in terms of syntax between a SSI code and a HTML comment is that SSI codes have a hash # following the tag opener.
Your server must support SSI in order to be able to take advantage of SSI commands. So how do you know if your server supports SSI? Well, first of all, most "free" web hosts, such as Geocities, Tripod, etc, do NOT support SSI...a rare exception is Hypermart. If your site's on a paid server, then this information should have been made available to you when you first signed on. If not, just send an email to your system administrator. Secondly, even if your server does support SSI, it's important to realize that most of them requires that you rename any HTML document that contains SSI from .html or .htm to .shtml. By doing so, the server knows that it should scan for and interpret SSI commands (instead of simply treating them as another HTML comment). Ok, now we're ready to officially see how to use SSI to dynamically embed a document inside another.
All include directives are formatted as SGML comments within your document. This is in case the document should ever be transferred without being parsed.
Each directive has the following format:
<!--#command tag1="value1" tag2="value2" -->
Each command takes different arguments, most only accept one tag at a time. Here is a breakdown of the commands and their associated tags:
include
config
other commands
include
Inserts the text of a specified document into the body of the current document. Is commonly used for including headers or footers in web pages.
Notes:
Do not leave any spaces between the equal ("=") sign and the file it specifies. Doing so will cause an error message to be displayed.
Any included file is subject to the usual access authorization controls.
If you use a domain name you must use the virtual command. file only works with WebCom URLs.
virtual
gives a virtual path to a document on the server. A normal file or another parsed document may be accessed using this tag. Please note that the path of this file name should be the URL of the file, with the domain name removed, and the userid added. For instance, if the URL of a file is "http://www.your-domain.com/products/footer.txt" and your userid is "userid" then the path to use with this include directive would be: "/userid/products/footer.txt"
Example: <!--#include virtual="/virtual_sample.txt"-->
This is a sample text file. It was included in this file by the include virtual tag:
<!--#include virtual="/webcom/virtual_sample.txt"-->.
This paragraph includes a hotlink, and tags such as bold and emphasis.
file
gives a pathname relative to the current directory. ../ cannot be used in this pathname, nor can absolute paths be used. (If you need to refer to a file in a higher directory, you might consider using virtual described above.) As above, you can send other parsed documents.
Example: <!--#include file="sample.txt"-->
This is a sample text file. It was included in this file by the include file tag: <!--#include file="sample.txt"-->.
This paragraph includes a hotlink, and tags such as bold and emphasis.
Including HTML in another HTML document
Sometimes, rather than linking to another document, it is helpful to include
the contents of an HTML document in another HTML document. We recommend
using the OBJECT element
with the data attribute
for this purpose.
For instance, the following line will include the
contents of piece_to_include.html at the location where the OBJECT
definition occurs.
...text before...
<OBJECT data="file_to_include.html">
Warning: file_to_include.html could not be included.
</OBJECT>
...text after...
The contents of OBJECT
must only be rendered if the file specified by the data
attribute cannot be loaded.
The behavior of a user agent in cases where a file includes itself is not
defined.
Careful file inclusions. Be careful if you
attempt to include a section of an HTML document defined by an anchor.
The entire document after the anchor definition will be included, and you
might unwittingly include unwanted end tags (for elements such as BODY,
HTML, etc.) in your document.
The IFRAME element
may also be used to insert an inline frame containing text in an HTML document.