article

Server Side Includes or SSI is an easy server-side scripting language used almost exclusively for the web. As its name implies, its primary use is including the contents of a file into another, via a Web Server.

SSI is primarily used to "paste" the contents of one or more files into another. For example, a file (of any type, .htm, .txt, etc.) containing a daily quote, could be included into multiple SSI Enabled pages throughout a website, by placing the following code into the desired pages. With one change of the quote.txt file, pages including the snippet will display the latest daily quote. Server Side Includes are useful for including a common piece of code throughout a site, such as a navigation menu.

In order for a web server to recognise a SSI-enabled HTML file and therfore carry out these instructions, the file must end with the .shtml extension. SSI files can also end with .shtm but this depends on the servers ability to recognise the extension.

Basic syntax


SSI has a simple syntax: <!--#directive parameter=value parameter=value-->. Directives are placed in HTML comments so that if SSI isn't enabled, users won't see the SSI directives on the page, unless they look at its source.

Directives


These are the most common SSI directives: specifies a server-side command; the cgi parameter specifies the path to a CGI script. The PATH_INFO and QUERY_STRING of the current SSI script will be passed to the CGI script. "include virtual" should be used instead of "exec cgi".
Directive Parameters Description Example
include file or virtual This is probably the most used SSI directive, allowing the content of one document to be included in another. The file or virtual parameters specify the file (HTML page, text file, script, etc) to be included. The file parameter defines the included file as relative to the document path; the virtual parameter defines the included file as relative to the document root.
exec cgi or cmd This directive executes a program, script, or shell command on the server. the cmd parameter
or
echo var This directive displays the contents of a specified HTTP environment variable. Variables include HTTP_USER_AGENT, LAST_MODIFIED, and HTTP_ACCEPT.
config timefmt, sizefmt, or errmsg This directive configures the display formats for the date, time, filesize, and error message (returned when an SSI command fails).
or

or
flastmod or fsize file or virtual These directives display the date when the specified document was last modified, or the specified document's size. The file or virtual parameters specify the document to use. The file parameter defines the document as relative to the document path; the virtual parameter defines the document as relative to the document root.
or
printenv   This directive outputs a list of all variables and their values, including environmental and user-defined variables. It has no attributes.

Examples


The methodology of embedding programming languages within HTML is called server-side include and the programming language that is embedded within the HTML is called the scripting language. Netscape's Server-side JavaScript (SSJS), Microsoft's Active Server Pages (ASP), Sun Microsystems' JavaServer Pages (JSP), and open source PHP are examples of server-side includes. They respectively use JavaScript, VBScript (or JScript), Java, and PHP as the scripting language.

External links


See also


Scripting languages

Server Side Includes | Server Side Includes | Server Side Includes | SSI | Server Side Includes

 

This article is licensed under the GNU Free Documentation License. It uses material from the "Server Side Includes".

Home Pageartsbusinesscomputersgameshealthhospitalshomekids & teensnewsphysiciansrecreationreferenceregionalscienceshoppingsocietysportsworld