SSI stands for Server Side Includes. What this means is that the server reads through the page for SSI directives. Wherever it finds these directives, it inserts the contents of files or the output of a CGI or other data, as defined by the SSI command.
This page demonstrates the types of SSI directives that you can use. There are other ways to write SSI directive, according to most manuals, but these are the only ways that appear to work at ProHosting. All the samples in this page were used in the page.
First, you need to be aware that only files that end with the extension ".shtml" will be parsed for SSI directives. The reason for this is that many times, people do not use SSI in their pages, so if the server had to parse all ".html" or ".htm" files for SSI directives, it would slow the server down. This way, the server only needs to parse files that end in ".shtml".
Including files means taking the contents of a file and placing it in the spot that your SSI directive is in the web page. This is useful for when you have the same header or footer information for a number of pages, you can have the header and footer in separate files and include them in all your pages. This lets you edit only the header and/or footer files alone instead of editing all your pages.
You can only include text-based files. This includes plain text and HTML, and similar files. You cannot use SSI to include things like image files and Java applets. However, the text can certainly contain HTML code that refers to image files or applets, and such.
The paths for referring to these files should be URL paths, meaning that they would be the same type of paths that you would use in your web browser or that you would use to refer to files from within your web pages.
<!--#include virtual="/~username/freefaq/include.txt" --><!--#include virtual="include.txt" --><!--#include virtual="../freefaq/include.txt" -->NOTE: This only works for including files in the the same directory as your .shtml file.
<!--#include file="include.txt" -->Including CGI output means taking the results of a CGI and placing it in the spot that your SSI directive is in the web page. This is useful for counter scripts or including ramdom links.
As with including files, the output of the CGI must be text, not binary data. However, the text can certainly contain HTML code that refers to image files or applets, and such.
The paths for referring to these files should be URL paths, meaning that they would be the same type of paths that you would use in your web browser or that you would use to refer to files from within your web pages.
NOTE: These will let you pass query string data.
<!--#include virtual="/~username/cgi-bin/faq_include.cgi" --><!--#include virtual="faq_include.cgi" --><!--#include virtual="../cgi-bin/faq_include.cgi" --><!--#include virtual="/~username/cgi-bin/faq_include.cgi?stuff=things" --><!--#include virtual="faq_include.cgi?stuff=things" --><!--#include virtual="../cgi-bin/faq_include.cgi?stuff=things" -->NOTE: These will not pass query string data, use #include virtual.
<!--#exec cgi="/~username/cgi-bin/faq_include.cgi" --><!--#exec cgi="faq_include.cgi" --><!--#exec cgi="../cgi-bin/faq_include.cgi" -->There are some other commands that you can use for SSI that can do things such as add the size of the file, the last modified date of the file, etc.
The paths for referring to these files should be URL paths, meaning that they would be the same type of paths that you would use in your web browser or that you would use to refer to files from within your web pages.
Prints the last modified time of the specified file. You can point to any file you own.
<!--#flastmod file="g_ssitest.shtml" --><!--#flastmod virtual="/~username/index.shtml" -->Prints the file size of the specified file. You can point to any file you own.
<!--#fsize file="g_ssitest.shtml" --><!--#fsize virtual="/~username/index.shtml" -->#flastmod and #fsize are used to get the last modified time and file size of any particular file, not just the file the SSI directive is in.
Configures the output for the #flastmod and #fsize directives.
<!--#config timefmt="%d/%m/%y" -->| Field | Description |
|---|---|
| %a | abbreviated weekday name |
| %A | full weekday name |
| %b | abbreviated month name |
| %B | full month name |
| %c | locale's appropriate date and time representation |
| %C | default date and time format |
| %d | day of month - 01 to 31 |
| %D | date as %m/%d/%y |
| %e | day of month - 1 to 31 (single digits are preceded by a blank) |
| %h | abbreviated month name (alias for %b) |
| %H | hour - 00 to 23 |
| %I | hour - 01 to 12 |
| %j | day of year - 001 to 366 |
| %m | month of year - 01 to 12 |
| %M | minute - 00 to 59 |
| %n | insert a new-line character |
| %p | string containing ante-meridiem or post-meridiem indicator (AM or PM) |
| %r | time as %I:%M:%S %p |
| %R | time as %H:%M |
| %S | second - 00 to 61, allows for leap seconds |
| %t | insert a tab character |
| %T | time as %H:%M:%S |
| %U | week number of year (Sunday as the first day of the week) - 00 to 53 |
| %w | day of week - Sunday = 0 |
| %W | week number of year (Monday as the first day of the week) - 00 to 53 |
| %x | Country-specific date format |
| %X | Country-specific time format |
| %y | year within century - 00 to 99 |
| %Y | year as ccyy (4 digits) |
| %Z | timezone name |
All other characters, such as spaces, slashes (/), periods (.), and commas (,) are printed as literals. E.g. <!--#config timefmt="%m/%d/%y" --> | |
<!--#config sizefmt="bytes" --><!--#config sizefmt="abbrev" --><!--#config errmsg="Some error occurred." -->"#echo" is used to display various environment variables. The complete list is below, however not all may work at all times from all browsers. Here is an example:
<!--#echo var="DOCUMENT_NAME" -->| Variable | Example | Description |
|---|---|---|
| SERVER_SOFTWARE | Apache | server application |
| SERVER_NAME | jove.prohosting.com | hostname of the server |
| SERVER_PROTOCOL | HTTP/1.1 | server protocol |
| SERVER_PORT | 80 | listening TCP port |
| REQUEST_METHOD | GET | HTTP method used by the client |
| REMOTE_HOST | (none) | domain name of the client, note DNS option must be set |
| REMOTE_ADDR | 69.12.127.10 | IP address of the client |
| AUTH_TYPE | (none) | method that the client used for authorization |
| REMOTE_USER | (none) | username entered by the remote client |
| CONTENT_TYPE | (none) | type of the content posted by the client |
| CONTENT_LENGTH | (none) | size of the data posted by the client |
| DOCUMENT_NAME | g_ssitest.shtml | name of the document requested |
| DOCUMENT_URI | /sampieri/freefaq/g_ssitest.shtml | URL of the document requested |
| DATE_LOCAL | Tuesday, 09-Feb-2010 19:32:06 MST | current date, format specified by the config command |
| DATE_GMT | Wednesday, 10-Feb-2010 02:32:06 GMT | the current GMT, format specified by the config command |
| LAST_MODIFIED | Thursday, 10-May-2001 21:53:17 MDT | document modified date, format specified by the config command |
| PAGE_COUNT | (none) | number of hits on the current document since server came on-line |
| TOTAL_HITS | (none) | number of documents server has served since coming on-line |
| REFERRER | (none) | the URL of the document the viewer came from |
For more detailed information on SSI, check this server-side includes tutorial.