UNIVERSITY of VIRGINIA
Computer Science
Research  Teaching  People  Community   

Search
Directory
Contact Us
 
Undergrads • Grad Students • Faculty • Staff • Alumni • Locator • Phones

Server-Side Includes Tutorial

Sample applications | File inclusion | Variable and function expansion | External executables | Counters | References

Server-parsed HTML documents (often calls "server-side includes," or "SSI" for short) are probably the easiest way to make a web page more dynamic without writing any actual code. This extension to HTML adds a small number of tags that the web server parses before sending the document to a client. The tags may cause another file to be read, an executable to be run, or a variable to be set or expanded.

Sample applications

Sample applications include (but are certainly not limited to):

File inclusion

[an error occurred while processing this directive]

Variable and functions expansion

Certain variables and functions can be expanded inline without running any external programs. Some examples -- tags paired with their output -- follow.

Description Tag Tag expansion
File size <!--#fsize virtual="/~webman/readme/ssi.shtml" --> [an error occurred while processing this directive]
Last date and time a file was modified <!--#flastmod virtual="/~webman/readme/ssi.shtml" --> [an error occurred while processing this directive]
The current document <!--#echo var="DOCUMENT_URI" --> /~webteam/readme/ssi.shtml
The remote hostname <!--#echo var="REMOTE_HOST" --> (none)
The remote browser <!--#echo var="HTTP_USER_AGENT" --> CCBot/2.0 (http://commoncrawl.org/faq/)
The current date and time <!--#echo var="DATE_LOCAL" --> Thursday, 19-Oct-2017 01:20:36 EDT

External executables

Server-side includes may also run other programs. These programs will be run as whichever user the web server runs as, often guest or nobody. For example, the server-side tag:
<!--#exec cmd="/bin/ls -l /home/webman/public_html/readme/ssi.shtml" -->
produces the following output:
-r--r--r-- 1 webman webstaff 9755 Jan 20 2002 /home/webman/public_html/readme/ssi.shtml

Here is another server-side tag:
<!--#exec cmd="/usr/cs/contrib/bin/fortune" -->
This generates a random quotation/fortune. Like this:


Hit reload for a different fortune.

This SSI loads a random picture. Note that only the inner tag (beginning with <!--) is an SSI. The outer tag is a conventional IMG tag that loads a different picture each time it is loaded.
<img src="<!--#exec cgi="/cgi-bin/randompicture" -->">

Hit reload for a different picture.

Counters (more external executables)

This SSI is a simple counter. The external executable counts the number of hits the page has received and prints it into the page.
<!--#exec cgi="/cgi-bin/counter" -->
[1]

This SSI is a Roman-numeral counter. The external executable counts the number of hits and converts it to a Roman numeral.
<!--#exec cgi="/cgi-bin/romcount" -->
[MMMMMMMMMMMMMDCCC]

Note that there are three different forms used for calling an external executable:


References

  • http://www.apache.org/docs/mod/mod_include.html - The Apache server-side includes documentation


  • UVa CS Department of Computer Science
    School of Engineering, University of Virginia
    151 Engineer's Way, P.O. Box 400740
    Charlottesville, Virginia 22904-4740

    (434) 982-2200  Fax: (434) 982-2214
    Web Comments: webteam@cs.virginia.edu
    Admissions Inquiries: inquiry@cs.virginia.edu
    Site directory, Other addresses
    Server statistics
    © Created by the CS Web Team