Server side includes

from Wikipedia, the free encyclopedia

Server Side Includes ( English for server-side integrations ), also known as SSI , are (usually HTML -) embedded documents, easy to use script commands running on the Web server to run before the document to the client is delivered. They are an easy-to-use alternative to programs or scripts that generate the entire document dynamically. The language is Turing-complete .

Emergence

SSI was originally introduced as an Apache module mod_ssi. Nowadays, other web servers also support the scripting language, including IIS from Microsoft .

use

With SSI, the static content of a file or the dynamic output of a program / script can be inserted into a document. The available commands are deliberately kept spartan: case distinctions , save and output variables , execute CGI programs or integrate other files.

syntax

Server side includes have the following syntax :

<!--#befehl parametername1="wert" parametername2="wert" -->

The introductory <!--and the final -->correspond to the characters for the beginning and the end of an HTML or XML comment and ensure that the browser does not display the commands if SSI is deactivated.

Important commands

command parameter description example
include file or virtual Ensures that the contents of the file are inserted. file addresses this file relative to the current directory, virtual relative to the root document directory. <!--#include file="header.shtml" -->

<!--#include virtual="script.pl" -->

set var , value or errmsg Writes the content of value to the variable var . Errmsg defines the standard error message that should be output for the next errors. Can e.g. B. can be placed in front of an SSI include and is displayed if the file cannot be loaded. <!--#set var="test" value="Hallo Welt!" --> or <!--#set errmsg="Es ist ein Fehler aufgetreten!" -->
echo var Returns variable var . These may involve user-defined variables or CGI - Environment Variables such. B. ${REMOTE_ADDR}. <!--#echo var="test" -->
exec cgi or cmd Executes the program cgi or the command cmd and inserts its output. <!--#exec cmd="ls -lsa" -->
if expr Checks the expression expr , valid are = equal,! = Not equal, <smaller,> larger or a regular expression . Several criteria can be strung together by adding || for OR or && for AND.

A practical use is, for example, the internationalization of a website:

<!--#if expr="${a} = ${b} || ${b} > 2 && ${a} != 0" --> HTML <!--#endif -->

<!--#if expr="$QUERY_STRING=/lang=FR/"-->
FR Inhalt
<!--#elif expr="$QUERY_STRING=/lang=EN/"-->
EN Inhalt
<!--#else--> DE Inhalt <!--#endif -->

X-bit hack

The web server usually recognizes HTML pages with server side includes by the file extension .shtml or .stm. This means that not all HTML pages have to be searched for SSI commands, which speeds up page delivery. However, to hide the use of SSI from the user, there is an alternative that was first introduced by the Apache web server. HTML files that contain SSI instructions are recognized by a special file attribute. This is what is known as the "X-bit hack". If this function in the Web server activated (eg., By the directive "XBitHack on" in the .htaccess file), all HTML pages in which the Execute bit ( execute is bit) set evaluated by the SSI interpreter before they are delivered to the client. Since the file rights are not visible from the client, the use of SSI can be hidden from the user.

Similar concepts

  • The programming languages PHP , ASP and JSP are syntactically related , in which dynamically generated code can be embedded in static HTML using a special identifier.

Web links

Individual evidence

  1. http://www.janschejbal.de/projekte/ssituring/ Server Side Includes Turing machine, Jan Schejbal, last accessed on August 12, 2010.