Server Side Includes

From Wikipedia, the free encyclopedia

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 in a default configuration to recognize an SSI-enabled HTML file and therefore carry out these instructions, the file must end with the .shtml extension. SSI files can also end with .shtm but this depends on the server's ability to recognize the extension. It is possible to configure a web server to recognize any file with the .html file extension for server side include processing.

Today, SSI has largely been replaced by the more complex programming languages PHP, ASP and JSP.

Contents

SSI has a simple syntax: . 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.

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

Directive Parameters Description Example
if expr Used for condition tests that may determine and generate multiple logical pages from one single physical page.

elif expr Serves the same purpose as further conditioning in programming langauges.


else If none of the if and elif directive catches the present condition, things in here should happen.



endif Termination of a conditional construct. See above for example.

The usual view is that SSIs are a handful of standard "directives" placed in an .html page in the form of "SGML" (e.g. standard HTML language) comments. It is old technology, but still useful.

The directives tell the server to look at the content of the document before sending it to the browser, and to take action if it sees one of these directives.

The most important directive is the "include" command:

This causes the server to insert the contents of "myincludefile.html" into the document being processed. It is effectively pasted into the document at the point where the directive is found. The include file may contain additional html commands, style sheets and even additional SSI directives.

Not all servers permit SSIs. Most Apache servers do. Check with your host first. There may be additional configurations needed to run them. Usually the including document must be named with a ".shtml" suffix, and the server has to be set to permit this.

One problem with SSIs, from the hosting point of view, is they slow down server processing. Another is that they create certain security concerns.

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.