|
Server
Side Includes (SSI)
- What
is a Server Side Include?
- Where
do I put Server Side Includes?
- When
I'm viewing my Web page in a browser, can I do view source with SSI
documents to see my code?
- What
are the major types of Server Side Includes?
What
is a Server Side Include?
Server
Side Includes are special HTML comments that are read by the Web server
software. The comment is removed and some other information is substituted.
For example the ssi/comment
<!--#echo
var="LAST_MODIFIED"-->
is
parsed (read in and processed) by the host, and this output results
Monday,
26-Jul-99 14:08:19 EDT
Where
do I put SSIs?
You
put these comments in your HTML documents. Most Web editors allow you
to insert an HTML comment anywhere in the document, or allow you to
edit the HTML source and add comments.
When
I'm viewing my Web page in a browser, can I do view source with SSI
documents to see my code?
Not
really. Because the ssi comments are removed, what you see in your browser
when you View Source is the result, not the original ssi. This means
that you must get the source via ftp download, or perhaps have it e-mailed
to you as an attachment.
What
are the major types of Server Side Includes?
There
are three: echo, exec, and include.
echo
is used to see the values of environment variables. The value of the
variable is inserted into your HTML document.
exec
is used to run (execute) a command or script on the host server, and
the output of that script is inserted into your HTML document.
include
inserts another HTML document into the middle of your document. In this
way, you join two or more documents together. This is usually used for
small pieces like toolbars, or navigational aids. You can only insert
files from the host where you Web page is served.
The
following is a list which typical values for a mythical user mst3k.
This list includes a larger than usual set of environment variables.
Normally, you won't have all these available. Only a few of these are
useful as SSIs. Quite a few are useful in writing CGI scripts.
CONTENT_LENGTH
= 48
CONTENT_TYPE = application/x-www-form-urlencoded
DATE_GMT = Friday, 29-Oct-99 16:06:07 EST
DATE_LOCAL = Friday, 29-Oct-99 12:06:07 EDT
DOCUMENT_NAME = home.html
DOCUMENT_PATH_INFO =
DOCUMENT_ROOT = /www/doc
DOCUMENT_URI = /~mst3k/home.html
GATEWAY_INTERFACE = CGI/1.1
HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
image/png, */*
HTTP_ACCEPT_CHARSET = iso-8859-1,*,utf-8
HTTP_ACCEPT_ENCODING = gzip
HTTP_ACCEPT_LANGUAGE = en
HTTP_CONNECTION = Keep-Alive
HTTP_HOST = www.people.virginia.edu
HTTP_IF_MODIFIED_SINCE = Fri, 29 Oct 1999 16:05:20 GMT; length=7617
HTTP_PRAGMA = no-cache
HTTP_USER_AGENT = Mozilla/4.5 [en] (WinNT; U)
LAST_MODIFIED = Friday, 29-Oct-99 12:06:03 EDT
PATH = /var/local/bin:/usr/bin:/usr/sbin:/usr/ucb:/bin
QUERY_STRING = findme=search&nid="1234%20"
QUERY_STRING_UNESCAPED = findme=search\&nid=\"1234 \"
REDIRECT_STATUS = 200
REDIRECT_URL = /~mst3k/
REMOTE_ADDR = 128.143.13.93
REMOTE_HOST = bootp-13-93.bootp.virginia.edu
REMOTE_PORT = 1327
REQUEST_METHOD = GET
SCRIPT_FILENAME = /home/mst3k/public_html/home.html
SCRIPT_NAME = /~mst3k/home.html
SERVER_ADMIN = jbb@virginia.edu
SERVER_NAME = www.people.Virginia.EDU
SERVER_PORT = 80
SERVER_PROTOCOL = HTTP/1.0
SERVER_SOFTWARE = Apache/1.2.4
TZ = EST5EDT
USER_NAME = mst3k |
Here
are the echo SSI statements to display these variables. Some of these
may only be available from a Perl script, and not available from SSI
in HTML files.
|
<!--#echo
var="DATE_GMT"-->
<!--#echo var="DATE_LOCAL"-->
<!--#echo var="DOCUMENT_NAME "-->
<!--#echo var="DOCUMENT_PATH_INFO"-->
<!--#echo var="DOCUMENT_ROOT"-->
<!--#echo var="DOCUMENT_URI"-->
<!--#echo var="GATEWAY_INTERFACE"-->
<!--#echo var="HTTP_CONNECTION"-->
<!--#echo var="HTTP_HOST"-->
<!--#echo var="HTTP_USER_AGENT"-->
<!--#echo var="HTTP_ACCEPT"-->
<!--#echo var="HTTP_ACCEPT_CHARSET"-->
<!--#echo var="HTTP_ACCEPT_ENCODING"-->
<!--#echo var="HTTP_ACCEPT_LANGUAGE"-->
<!--#echo var="HTTP_CONNECTION"-->
<!--#echo var="HTTP_HOST"-->
<!--#echo var="HTTP_IF_MODIFIED_SINCE"-->
<!--#echo var="HTTP_PRAGMA"-->
<!--#echo var="HTTP_USER_AGENT"-->)
<!--#echo var="LAST_MODIFIED"-->
<!--#echo var="PATH"-->
<!--#echo var="QUERY_STRING"-->
<!--#echo var="QUERY_STRING_UNESCAPED"-->
<!--#echo var="REDIRECT_STATUS"-->
<!--#echo var="REDIRECT_URL"-->
<!--#echo var="REMOTE_ADDR"-->
<!--#echo var="REMOTE_HOST"-->
<!--#echo var="REMOTE_PORT"-->
<!--#echo var="REQUEST_METHOD"-->
<!--#echo var="REQUEST_URI"-->
<!--#echo var="SCRIPT_FILENAME"-->
<!--#echo var="SCRIPT_NAME"-->
<!--#echo var="SERVER_ADMIN"-->
<!--#echo var="SERVER_NAME"-->
<!--#echo var="SERVER_PORT"-->
<!--#echo var="SERVER_PROTOCOL"-->
<!--#echo var="SERVER_SOFTWARE"-->
<!--#echo var="TZ"-->
<!--#echo var="USER_NAME "-->
<!--#include
virtual="filename.html"-->
<!--#include virtual="subdirectory/filename.html"-->
<!--#exec
cmd="myscript.pl"-->
<!--#exec cmd="subdirectory/myscript.pl"-->
<!--#exec
cgi="cgiscript.cgi"-->
<!--#exec cgi="subdirectory/cgiscript.cgi"-->
|
|