Server Side Includes (SSI) Documentation
A server side include, or SSI, is a piece of code that is embedded into an HTML page and interpreted by the the server before the page is sent to the client's browser. SSI's allow you to include information in your HTML files like a file's date of last modification, another HTML file, a counter, or the output of any CGI script.
Server Side Includes are server intensive. Because all files need to be parsed by the server, having all of your pages SSI would cut performance.
Any file that has the extension .shtml will automatically be parsed by the server. You can use index.shtml
instead of index.html as your default directory file.
Syntax must be correct, or your include will not work.
The include command has two possible arguments: virtual and file.
"Virtual" is used when the path to the document is given relative to the document root (usually your www directory.)
"File" is used when the path to the document is given relative to the shtml file itself. However, you cannot use "file" to go up a directory ( "../slime.html" won't work.)
Say we want to include the file named "file.html" which resides in the same sub directory of as this shtml file.
This would return: This is from file.html
This would return: This is from
file.html
If you look carefully you will notice
the second line uses the statement exec cgi opposed to the previous
line which used exec cmd. The second line is calling a CGI script
that was written, the first a UNIX command. Here is the perl code contained
in hello.cgi:
#!/bin/perl
print "Hello";
exit;
All the environment variables passed to the CGI script are the same as those for the shtml file itself.
So, you cannot pass a query string using a question mark (?), as in:
<!--#exec cmd="hello.cgi?query" -->
The query string passed to the CGI script will be the same as the query string passed to the shtml file itself. If this file were referenced as "ssi.shtml?snort", than the word "snort" would also be passed to the "hello.cgi" script above.
To find the size of picture.gif, you would use:
<!--#fsize virtual="graphics/picture.gif" -->
This would return then return the file size.
Your probably now asking, what can I use this for? Example: You offer some files available for download on your site and would like to give people an idea of how big the files are.
The flastmod command uses the argument "virtual," which is the path to the file is given relative to the document root (usually your www directory.)
To find the last modified date of a file, you would use:
<!--#flastmod virtual="filename.txt" -->
This would return: Friday, 06-Sep-96 03:36:06 EDT
To set the format for the date to dd/mm/yy, you will use:
<!--#config timefmt="%d/%m/%y" -->
The date will now be displayed as: 03/06/97
The field descriptors used by this SSI tag are the same as those used by the Unix date command.
Notice the dates displayed above this config command use the normal date format, the one below it uses the new format.
To set the format for how file sizes are displayed, you use:
<!--#config sizefmt="abbrev" -->
or:
<!--#config sizefmt="bytes" -->
Depending on whether you want the size given in total bytes or abbreviated as "1k".
To set error message returned when an SSI tag fails, use:
<!--#config errmsg="Error" -->
A failed SSI tag will now return: Error
© Copyright WEBMASTERS.COM. All Rights Reserved.