Server-side scripting is a web server technology in which a user's request is verified by running a script directly on the web server to generate dynamic web pages. It is usually used to provide interactive web sites that interface to databases or other data stores. This is different from...
The World Wide Web is a system of interlinked hypertext documents accessed via the Internet...
.
The most frequent use of SSI is to include the contents of one or more files into a web page on a web server
Web server
Web server can refer to either the hardware or the software that helps to deliver content that can be accessed through the Internet....
. For example, a web page containing a daily quotation could include the quotation by placing the following code into the file of the web page:
With one change of the quote.txt file, all pages including the file will display the latest daily quotation. The inclusion is not limited to files, and may also be the text output from a program, or the value of a system variable such as the current time.
Server Side Includes are useful for including a common piece of code throughout a site, such as a page header, a page footer and a navigation menu. Conditional navigation menus can be conditionally included using control directives.
In order for a web server to recognize an SSI-enabled HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
file and therefore carry out these instructions, either the filename should end with a special extension
Filename extension
A filename extension is a suffix to the name of a computer file applied to indicate the encoding of its contents or usage....
, by default .shtml, .stm, .shtm, or, if the server is configured to allow this, set the execution bit of the file.
As a simple programming language, SSI supports only one type
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...
In computer science, control flow refers to the order in which the individual statements, instructions, or function calls of an imperative or a declarative program are executed or evaluated....
is rather simple, choice is supported, but loops are not natively supported and can only be done by recursion using include or using HTTP redirect. The simple design of the language makes it easier to learn and use than most server-side scripting languages, while complicated server-side processing is often done with one of the more feature-rich programming languages. SSI is Turing complete
Turing completeness
In computability theory, a system of data-manipulation rules is said to be Turing complete or computationally universal if and only if it can be used to simulate any single-taped Turing machine and thus in principle any computer. A classic example is the lambda calculus...
The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...
nginx is a Web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage. It is licensed under a BSD-like license and it runs on Unix, Linux, BSD variants, Mac OS X, Solaris, and Microsoft Windows.- Overview...
lighttpd is an open-source web server more optimized for speed-critical environments than common products while remaining standards-compliant, secure and flexible...
Internet Information Services – formerly called Internet Information Server – is a web server application and set of feature extension modules created by Microsoft for use with Microsoft Windows. It is the most used web server after Apache HTTP Server. IIS 7.5 supports HTTP, HTTPS,...
are the four major web servers that support this language.
Basic syntax
SSI has a simple syntax: <!--#directive parameter=value parameter=value -->. Directives are placed in HTML comments so that if SSI is not enabled, users will not see the SSI directives on the page, unless they look at its source. Note that the syntax does not allow spaces between the leading "<" and the directive.
Most common directives
Directive
Parameters
Description
Example
include
file, direct 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
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
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.
Apache tutorial on SSI stipulates the format requires a space character before the "-->">that closes the element.
include
file or virtual
Includes the contents of another file or the result of running a CGI
Common Gateway Interface
The Common Gateway Interface is a standard method for web servers software to delegate the generation of web pages to executable files...
script. If the process does not have access to read the file or execute the script, the include will fail. "virtual" specifies the target relative to the domain root, while "file" specifies the path relative to the directory of the current file. When using "file" it is forbidden to reference to absolute paths. Higher directories (..) are usually forbidden, unless explicitly configured. The Apache documentation recommends using "virtual" in preference to "file".
or
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
Common Gateway Interface
The Common Gateway Interface is a standard method for web servers software to delegate the generation of web pages to executable files...
script. The PATH_INFO and QUERY_STRING of the current SSI script will be passed to the CGI script, as a result "exec cgi" should be used instead of "include virtual".
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.They can be said in some sense to create the operating environment in which a process runs...
. 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.
Control directives
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 languages.
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.
set
var, value
Sets the value of a SSI variable. (Not supported by all implementations)
The command is supported in both Apache httpd and lighttpd.
Client Side Includes
Client Side Includes are HTML includes achieved on the client-side
Client-side
Client-side refers to operations that are performed by the client in a client–server relationship in a computer network.Typically, a client is a computer application, such as a web browser, that runs on a user's local computer or workstation and connects to a server as necessary...
. This means that the inclusions can be cached on the client. It also means that web pages with includes can be viewed locally on the file system without a web server.
However, while HTML allows the direct inclusion of CSS, JavaScript and Image files into a web page it has never allowed direct inclusion of HTML. There are several tricks to achieve this, each with their own problems. These include:-
Ajax is a group of interrelated web development methods used on the client-side to create asynchronous web applications...
to load the HTML. No modern web browsers will generally allow this to work directly from the file system due to security concerns.
These client-side includes are relatively complex, are not accessible to WYSIWYG
WYSIWYG
WYSIWYG is an acronym for What You See Is What You Get. The term is used in computing to describe a system in which content displayed onscreen during editing appears in a form closely corresponding to its appearance when printed or displayed as a finished product...
editors, and rely on the client's support of their respective technologies. In the case of frames and iframes, they are less accessible.
At first it seems that manually copying and recopying HTML fragments from page to page is the easiest way, but SSI/CSI pays off. In the future, browsers may implement the W3C XInclude
XInclude
XInclude is a generic mechanism for merging XML documents, by writing inclusion tags in the "main" document to automatically include other documents or parts thereof. The resulting document becomes a single composite XML Information Set...
specification which enables client-side includes. Similarly, client-side XML includes may be done in some browsers today through the use of DTD
Document Type Definition
Document Type Definition is a set of markup declarations that define a document type for SGML-family markup languages...