SSI Test

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.

  1. File Extensions
  2. Including Files
  3. Including CGI Output
  4. Other Includes

.   File Extensions

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

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=
#include file=

NOTE: This only works for including files in the the same directory as your .shtml file.

.   Including CGI Output

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.

#include virtual=

NOTE: These will let you pass query string data.

#exec cgi=

NOTE: These will not pass query string data, use #include virtual.

.   Other Includes

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.

#flastmod

Prints the last modified time of the specified file. You can point to any file you own.

#fsize

Prints the file size of the specified file. You can point to any file you own.

#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.

#config

Configures the output for the #flastmod and #fsize directives.

#echo

"#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" -->
g_ssitest.shtml

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.