Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Server Side Includes
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Interpreted server-side scripting language}} '''Server Side Includes''' ('''SSI''') is a simple interpreted [[server-side scripting]] language used almost exclusively for the [[World Wide Web]]. It is most useful for including the contents of one or more files into a web page on a [[web server]] (see below), using its <code>#include</code> directive. This could commonly be a common piece of code throughout a site, such as a page header, a page footer and a navigation menu. SSI also contains control directives for conditional features and directives for calling external programs. It is supported by [[Apache HTTP Server|Apache]], [[LiteSpeed Web Server|LiteSpeed]], [[nginx]], [[Internet Information Services|IIS]] as well as [[W3C]]'s Jigsaw.<ref name=jig>{{cite web |title=SSI Commands |url=https://www.w3.org/Jigsaw/Doc/User/SSI.html |website=W3C |access-date=24 March 2019}}</ref> It has its roots in [[NCSA HTTPd]].<ref name="ncsa-ssi"/> In order for a web server to recognize an SSI-enabled [[HTML]] file and therefore carry out these instructions, either the filename should end with a special [[Filename extension|extension]], by default <code>.shtml</code>, <code>.stm</code>, <code>.shtm</code>, or, if the server is configured to allow this, set the execution bit of the file.<ref>{{cite web|title=Configuring your server to permit SSI|url=http://httpd.apache.org/docs/current/howto/ssi.html#configuring|website=Apache Tutorial: Introduction to Server Side Includes|publisher=The Apache Software Foundation|access-date=24 June 2015}}</ref> == Design == As a simple programming language, SSI supports only one [[Data type|type]]: text. Its [[control flow]] is rather simple, choice is supported, but [[Control_flow#Loops|loops]] are not natively supported and can only be done by recursion using include or using [[URL redirection|HTTP redirect]].{{efn|Nevertheless found in some implementations, including Jigsaw.}} 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 [[Server-side scripting#Languages|one of the more feature-rich programming languages]]. SSI is [[Turing completeness|Turing complete]].<ref>{{cite web|url=http://www.janschejbal.de/projekte/ssituring/ |title=Server Side Includes Turing machine, Jan Schejbal. |publisher=Janschejbal.de |access-date=2012-12-06}}</ref> SSI has a simple syntax: <code><!--#directive parameter=value parameter=value --></code>. 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. Apache tutorial on SSI stipulates the format requires a space character before the "-->" that closes the element.<ref>{{cite web|url=http://httpd.apache.org/docs/current/howto/ssi.html#basic|title=Basic SSI Directives and Syntax|access-date=2018-02-09|date=2018-02-09}}</ref> == Examples == A web page containing a daily quotation could include the quotation by placing the following code into the file of the web page: <syntaxhighlight lang="xml"> <!--#include virtual="../quote.txt" --> </syntaxhighlight> With one change of the <code>quote.txt</code> file, all pages that include 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. == Directives == === Common === The following are SSI directives from the times of [[NCSA HTTPd]] (the 1990s).<ref name="ncsa-ssi">{{cite web |title=Server Side Includes (SSI) |url=http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html |website=NCSA HTTPd Tutorial |access-date=24 March 2019 |archive-url=https://web.archive.org/web/19970303194503/http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html |archive-date=3 March 1997|url-status=dead}}</ref> Some implementations do not support all of them.<ref name=nginx-ssi>{{cite web |title=Module ngx_http_ssi_module |url=http://nginx.org/en/docs/http/ngx_http_ssi_module.html |website=nginx documentation |access-date=16 November 2021}}</ref> {| class="wikitable" |+NCSA HTTPd SSI directives |- ! Directive ! Parameters ! Description ! Example |- | <code>include</code> | file or virtual | This is probably the most used SSI directive. It allows the content of one document to be [[Transclusion|transcluded]] in another. The included document can itself be another SSI-enabled file. The <code>file</code> or <code>virtual</code> parameters specify the file ([[HTML]] page, text file, script, etc.) to be included. NCSA HTTPd did not support [[Common Gateway Interface|CGI]] via <code>include</code>,<ref name="ncsa-ssi"/> but later Apache HTTPd does.<ref name="apache-httpd-doc-mod-include">{{cite web | url = http://httpd.apache.org/docs/current/mod/mod_include.html#element.include | title = Apache Module mod_include | work = Apache HTTP Server Version 2.4 Documentation | publisher = Apache Software Foundation | access-date = 2021-09-07 }}</ref> If the process does not have access to read the file or execute the script, the include will fail. The parameter "<code>virtual</code>" handles any directory paths as if part of the URL, while "<code>file</code>" handles any directory paths as in the underlying filesystem. When using "<code>file</code>" it is forbidden to reference absolute paths or <code>../</code> to access a parent directory. The Apache documentation recommends using "<code>virtual</code>" in preference to "<code>file</code>".<ref name="apache-httpd-doc-mod-include"/> | <pre style="white-space:pre"><nowiki> <!--#include virtual="menu.cgi" --> <!--#include file="footer.html" --></nowiki></pre> |- | <code>exec</code> | 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 [[Common Gateway Interface|CGI]] script. {{cns|date=September 2021|The <code>PATH_INFO</code> and <code>QUERY_STRING</code> of the current SSI script will be passed to the CGI script, as a result "exec cgi" should be used instead of "include virtual".}} | <pre style="white-space:pre"><nowiki> <!--#exec cgi="/cgi-bin/foo.cgi" --> <!--#exec cmd="ls -l" --></nowiki></pre> |- | <code>echo</code> | var | This directive displays the contents of a specified [[HTTP]] [[environment variable]]. {{cns|date=September 2021|Variables include <code>HTTP_USER_AGENT</code>, <code>LAST_MODIFIED</code>, and <code>HTTP_ACCEPT</code>.}} | <pre style="white-space:pre"><nowiki>Your IP address is: <!--#echo var="REMOTE_ADDR" --></nowiki></pre> |- | <code>config</code> | timefmt, sizefmt, or errmsg | This directive configures the display formats for the date, time, filesize, and error message (returned when an SSI command fails). | <pre style="white-space:pre"><nowiki><!--#config timefmt="%y %m %d" --> <!--#config sizefmt="bytes" --> <!--#config errmsg="SSI command failed!" --></nowiki></pre> |- | <code>flastmod</code> and <code>fsize</code> | 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. | <pre style="white-space:pre"><nowiki><!--#flastmod virtual="index.html" --> <!--#fsize file="script.pl" --></nowiki></pre> |} === Control directives === Control directives are later added to SSI. They include the ubiquitous if-elif-else-endif flow control and variable writing as well as more exotic features like loops only found in some implementations. {| class="wikitable" |- ! Directive ! Parameters ! Description ! Example ! Found in |- | {{plainlist| * if * elif * else * endif }} | expr | The [[if statement]]. Used for condition tests that may determine and generate multiple logical pages from one single physical page. <code>elif</code> is a shorthand for nested else-if. <code>else</code> and <code>endif</code> do not accept parameters. Expression syntax vary among implementations. Variable existence and equality/regex checks are commonly supported. Jigsaw uses expressions split over multiple attributes instead.<ref name=jig/> | <pre style="white-space:pre"><nowiki> <!--#if expr="${Sec_Nav}" --> <!--#include virtual="secondary_nav.txt" --> <!--#elif expr="${Pri_Nav}" --> <!--#include virtual="primary_nav.txt" --> <!--#else --> <!--#include virtual="article.txt" --> <!--#endif --> </nowiki></pre> | Ubiquitous. |- | set | var, value | Sets the value of a SSI variable. Apache provides additional parameters for [[encoding]]s.<ref name=apache-inc/> | <pre style="white-space:pre"><nowiki><!--#set var="foo" value="bar" --></nowiki></pre> | Apache,<ref name=apache-inc>{{cite web |title=mod_include |url=https://httpd.apache.org/docs/current/mod/mod_include.html |website=Apache HTTP Server |access-date=25 March 2019}}</ref> Nginx<ref name="nginx">{{cite web |title=ngx_http_ssi_module |url=https://nginx.org/en/docs/http/ngx_http_ssi_module.html |website=nginx.org |access-date=25 March 2019}}</ref> |- | <code>printenv</code> | | This directive outputs a list of all SSI variables and their values, including environmental and user-defined variables. It has no attributes. | <pre style="white-space:pre"><nowiki><!--#printenv --></nowiki></pre> | Apache<ref name=apache-inc/> |} == See also == *[[Edge Side Includes|ESI (Edge Side Includes)]] == Notes == {{notelist}} == References == {{Reflist}} == External links == * Language reference from implementations: ** Apache: [http://httpd.apache.org/docs/current/mod/mod_include.html Apache mod_include Reference]. Calls directives "elements". ** Nginx: [https://nginx.org/en/docs/http/ngx_http_ssi_module.html Module ngx_http_ssi_module]. Calls directives "commands". ** [[NCSA HTTPd]]: [https://web.archive.org/web/19971210170837/http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html Original NCSA HTTPd SSI Reference]. Calls directives "commands". ** W3C Jigsaw: [https://www.w3.org/Jigsaw/Doc/User/SSI.html Server Side Include commands]. Calls directives "elements". Highly expanded with [[servlet]]s, [[JDBC]], [[HTTP cookie]], and loops. * Tutorials: **[http://httpd.apache.org/docs/current/howto/ssi.html Apache SSI Tutorial] ** [http://www.andreas.com/faq-ssi.html Plain-English Guide to SSI] ** [http://www.ssi-developer.net/ssi/ SSI-Developer, Apache Server Side Includes] {{Web interfaces}} <!--Interwikies--> [[Category:Scripting languages]] [[Category:Web 1.0]] [[Category:Web technology]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite web
(
edit
)
Template:Cns
(
edit
)
Template:Efn
(
edit
)
Template:Notelist
(
edit
)
Template:Plainlist
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Web interfaces
(
edit
)