Server-side includes are html comments containing special flags which cause the server to substitute into the html document before displaying it.
The following examples are for the Apache Web Server:
Below is an example of SSI code to restrict a portion of a paragraph for USGS-only display and another portion for non-USGS only display.
<!--#if expr="${REMOTE_HOST} = /.usgs.gov$/ || ${REMOTE_HOST} = /.gs.doi.net$/" -->
<p><b>Display this text to internal user's only!</b></p>
<!--#endif -->
Display this text to internal user's only!
An example of how to detect the user's browser:
<!--#if expr="${HTTP_USER_AGENT} = /Firefox/" -->
<p><b>You are using FireFox.</b></p>
<!--#else -->
<p><b>You are not using FireFox.</b></p>
<!--#endif -->
You are using FireFox
Below are a few of the available variables.
IGSAWS910SVPWE1.GS.DOI.NET
Virtual uses paths as a web browser sees them (starting from DocumentRoot), and file can see the full Unix directory structure. Virtual is encouraged for including files found in the web directory.
The extension .htmli is often used to distinguish include files, which include html code but are not complete html documents, from text files.
Note: In Apache 2.0, virtual becomes recursive, that is, included files can also have includes.
The date format options can be seen using the Unix command: man strftime; You can skip first section describing the C library function.
On Sun, edit one file /usr/local/apache/etc/httpd.conf to change the same options as above; Options and AddType.
Only files with the suffixes defined by AddType
will be parsed for SSIs! If you Include any files
which in turn contain SSIs, these also must have an appropriate
file suffix.
A common use of SSI is to share a bit of html code among many files, such as banner or footer information, with a simple include.
Programs invoked through exec can range from
very simple to very complex. An example of SSI programming is a
self-expiring "new" icon
that goes away when a time limit is exceeded. Programs executed
from a server-side include have access to the same
environment variables as those using CGI.
Another useful SSI program is classgrep, which can extract portions of other documents on your web site and include them on any number of other pages, or documents. For example, <!--#classgrep alert virtual="/news.html"--> will extract the contents of any tag with the attribute "alert" found in the news.html file and insert it in place of the SSI. You can also use DIV tags to surround as much html code as you like. It even has an option for random selections by using a -r option following the classgrep command.(use classgrep -r class virtual="/news.html"> for one item to be selected, or -r2, or -r3 .
Server-Side Includes can be turned on or off, or may be on but have "exec" disabled.
The official description of Apache SSI is available on the Apache Web site: http://httpd.apache.org/docs/mod/mod_include.html
slide 49
|
"Mastering a Web Site" online course Created and maintained by Lorna Schmid and David Boldt. http://water.usgs.gov/usgs/training/webmaster/ssi.html Last modified: Wed Jul 18 14:00:27 EDT 2007 |