FAQ's about Server Side Includes


Q. What are server side includes ?

A. Server Side Includes (SSI) are commands that are embedded within HTML comments ( <!-- --> ) that the web server looks for, and replaces with information on the fly. If you read the rest of this document, you will see several server side includes in action.


Q. What special needs to be done ?

A. All the files containing server side includes scripts needs to end with the ".shtml" extension. If you would like to execute server side includes from a file not ending with the ".shtml" extension, please refer the the below question "How do I make files that don't end in *.shtml server parseable?"


Q. Do server side includes have any bad sides ?

A. Web pages with server side includes, and files that are specified by the web server to be server parsed, will take longer to load than a non-server parsed web page. This is because the web server actually has to read each line of the web page when it is looking for the server side include commands.


Q. How do I make files that don't end in *.shtml server parseable ?

A. In order for the server to think your *.html files are server parseable, you will need to add the following line to your existing .htaccess file (or make a new .htaccess file):
AddType text/x-server-parsed-html .html
this will make *all* *.html files server-parsed. (if your files are *.htm put .htm instead).

By adding this line, our server will make all files that end in .shtml server parsed.


Q. I'm using PERL, how can I get access to the server side include information ?

A. PERL has a variable named $ENV that contains the environment of the script. To get access to any of the server side variables, just reference them with $ENV{'variable-name'}. For example, to get the DATE_LOCAL, use: $ENV{'DATE_LOCAL'}.


Q. How do I use server side includes in my web pages ?

A. Server side includes are powerful ways to add functionality to your web pages. Our web server supports many of the standard NCSA web server server side includes. Below is a list of all server side includes supported.

Server side includes have the following format, and are to be placed inside your *.shtml or other SERVER-PARSED web pages.

<!--#COMMAND LABEL=["]ARGUMENT(S)["]-->
The easiest way to make a server side include work, is to rename your *.html file to *.shtml.

Our server is pre-configured to have *.shtml files be server-parsed (i.e., the server will read each *.shtml file and look for server side include commands). If you don't want to rename your files *.shtml, you can edit your .htaccess file and make *.html be server parsed.

Some commands require quotes, others do not. Exact syntax is shown in the examples below.

CommandLabelArgument(s)ExampleDescription
execcgicgi to run relative to current directory <!--#exec cgi="mycgi.cgi"-->This will run the cgi specified in the argument
cmdShell command to execute<!--#exec cmd="whoami"-->This executes the specified commands using the Bourne Shell (/bin/sh). This command is NOT expected to generate any MIME headers.
configtimefmtstrftime formatting string<!--#config timefmt="%c"-->Will change the current configuration of the time variables (way that the time and date are displayed)
sizefmtb, K, M (file size options)<!--#config sizefmt=k--> This determines how the fsize command displays file sizes
includefilefilename relative to current directory<!--#include file="myfile.txt"--> This will insert the contents of the file specified into the current page. The contents of the included file are not parsed.
fsizefilefilename relative to current directory<!--#fsize file="myfile.txt"-->This inserts the size of the specified file. This is controlled by the config sizefmt command.
flastmodfilefilename relative to current directory<!--#flastmod file="myfile.txt"-->This inserts the last modification time/date of the specified file. This command is controlled by the config timefmt command and the strftime formatting string
echovarEnviroment variable from the following:<!--#echo var=VARIABLE-->Used to show the contents of a server variable. Below are the variables that our server will display. Note, some are browser dependant.
ArgumentResult
AUTH_TYPE
If the server supports user authentication, and the script is protects, this is the protocol-specific authentication method used to validate the user.
If viewing a password protected web page, this will be the "authentication type".
CONTENT_LENGTH
The length of the said content as given by the client.
CONTENT_TYPE
For queries which have attached information, such as HTTP POST and PUT, this is the content type of the data.
DATE_GMT
Same as DATE_LOCAL but in Greenwich mean time (GMT).
DATE_LOCAL
The current date, local time zone. Subject to the timefmt parameter to the config command.
DOCUMENT_NAME
This file's name.
DOCUMENT_ROOT
The location on disk of the server's primary web site.
DOCUMENT_URI
This document's URI. (path and filename)
GATEWAY_INTERFACE
The revision of the CGI specification to which this server complies.
General Format: CGI/revision.
HTTP_USER_AGENT
The "user agent" or web browser that the visitor is using.
General Format: software/version, library/version
HTTP_REFERER
* only works if you came here by following a link from another page.
This shows the referring document. If a visitor came to this page by following a link, the URL they came from will be shown here.
HTTP_ACCEPT
The MIME types which the client will accept, as given by HTTP headers. Other protocols may need to get this information from elsewhere. Each item in this list should be separated by commas as per the HTTP spec.
General Format: type/subtype, type/subtype
HTTP_ACCEPT_LANGUAGE
The language that the visitor's web browser will accept.
HTTP_CONNECTION
Comments coming soon.
HTTP_HOST
Similar to SERVER_NAME.
HTTP_UA_COLOR
*Microsoft IE Tag
The type of display that the visitor is using, normally "color" followed by a decimal number representing how many bits, 8 being 256 colors.
HTTP_UA_CPU
*Microsoft IE Tag
The CPU type of the visitor's computer.
HTTP_UA_OS
*Microsoft IE Tag
The operating system in use by the visitor.
HTTP_UA_PIXELS
*Microsoft IE Tag
The dimensions of the visitor's web browser display in pixels. Standard VGA is 640x480.
LAST_MODIFIED
The last modification date of the current document. Subject to timefmt like the others.
PATH
The paths available to the "nobody" user of the web server.
PATH_INFO
The extra path information, as given by the client. In other words, scripts can be accessed by their virtual pathname, followed by extra information at the end of this path. The extra information is sent as PATH_INFO. This information should be decoded by the server if it comes from a URL before it is passed to the CGI script.
PATH_TRANSLATED
The server provides a translated version of PATH_INFO, which takes the path and does any virtual-to-physical mapping to it.
QUERY_STRING
The information which follows the ? in the URL which referenced this script. This is the query information. It should not be decoded in any fashion. This variable should always be set when there is query information, regardless of command line decoding.
QUERY_STRING_UNESCAPED
The unescaped version of any search query the client sent, with all shell-special characters escaped with \.
REMOTE_ADDR
The IP address of the remote host making the request.
REMOTE_HOST
The translated name of the hostname making the request. If the server does not have this information, it should set REMOTE_ADDR and leave this unset.
REMOTE_IDENT
If the HTTP server supports RFC 931 identification, then this variable will be set to the remote user name retrieved from the server. Usage of this variable should be limited to logging only.
REMOTE_USER
If the server supports user authentication, and the script is protected, this is the username they have authenticated as. If viewing a password protected web page, this will be the "username".
REQUEST_METHOD
The method by which the visitor's web browser is retrieving the web pages. For HTTP, this is "GET", "HEAD", "POST", etc.
SERVER_ADMIN
The administrator's email address configured in the server configuration file for this virtual domain name.
SERVER_NAME
The server's hostname, DNS alias, or IP address as it would appear in self-referencing URLs.
SERVER_PORT
The port this web server is running on. 80 is the standard http/web port.
SERVER_PROTOCOL
The name and revision of the information protcol this request came in with.
General Format: protocol/revision.
SERVER_SOFTWARE
The name and version of the information server software answering the request (and running the gateway).
General Format: name/version.
SCRIPT_FILENAME
UNIX path name to the script being executed.
SCRIPT_NAME
A virtual path to the script being executed, used for self-referencing URLs.