| Search Directory Contact Us | ![]() | ||||||||||||||||||||
![]() | ||||||||||||||||||||||
| Undergrads Grad Students Faculty Staff Alumni Locator Phones | ||||||||||||||||||||||
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):
- Counters
- Random picture selectors
- Random quotation (fortune) generators
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" --> WebVac (nee Pita) (webmaster@pita.stanford.edu) The current date and time <!--#echo var="DATE_LOCAL" --> Wednesday, 02-Oct-2013 13:40:03 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.shtmlHere 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" -->
[DXLV]Note that there are three different forms used for calling an external executable:
- <!--#exec cmd="path" --> takes an absolute path runs any executable.
- <!--#exec cgi="path" --> takes a relative path (like a URL) and runs CGI-style executables. The executable is responsible for returning a content-type header. This method is preferred over "exec cmd" because it uses relative paths and allows redirection.
- <!--#include virtual="path" --> takes also takes a relative path, but unlike "exec cgi", it detects whether the specified file is a script to run or a file to include. This is the best method to use.
References
http://www.apache.org/docs/mod/mod_include.html - The Apache server-side includes documentation
| | ||
| 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 |