|
SSI
- Server
Side Includes
Introduction
SSI, or Server-Side Includes, can make maintaining Web pages easier.
At the core, SSI
enables web servers to make slight modifications to HTML documents
before sending them to a requesting client(browser). The changes
the web server makes are controlled by SSI commands that are embedded
in the HTML document. For example, there are SSI commands that
instruct the Web server to include another file in the HTML file
or print information about the file. All SSI documents must use
the filename extension allowed by the web server (i.e. .shtml
on Apache). In other words, to make use of SSI on Vaxxine,
your HTML documents must have the .shtml extension ie. mywebpepage.shtml
To include an SSI command in an HTML document, you simply embed
the command into the source code of the document at the point
where you want the server to execute the command. All SSI commands
are case-sensitive and use the following general syntax:
<!--#element
attribute="value" -->
For example,
using the SSI code: <!--#echo var="HTTP_USER_AGENT"
-->
We end up
with...
CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
What did
we do? That's right, we used SSI to grab some information about
your web browser, and printed it on this page!
Elements and Attributes
of SSI:
| Element |
Attribute |
Description |
| echo |
var |
displays
the value of environment variables, special SSI variables,
and any user-defined variables. |
| include |
|
inserts
contents of a file into the current document. |
| |
file |
path
of file relative to current dir (no absolute paths, reference
files outside of document root); the file contents are included
directly into the page with no additional processing. |
| |
virtual |
Virtual
path (URL) relative to the document, the server interprets
the path as if it were any old HTTP request, so you can use
this to insert results of a CGI program or another SSI document. |
| fsize |
|
inserts
the size of a file. |
| |
File |
Path
of file relative to current directory. |
| |
Virtual |
Virtual
path (URL) relative to current directory. |
| flastmod |
file |
Inserts
last modification date and time for a specified file (local) |
| exec |
|
Executes
external programs and inserts output in current dir (unless
SSI has been configured with IncludeNoExec). |
| |
cmd |
|
| |
cgi |
|
| printenv |
|
Displays
a list of env't vars. and their values (useful when debugging
on a new server). |
| set |
var |
Sets
the value for a new or existing env't variable; the variable
only lasts throughout the current request (but is available
to CGI scripts or other SSI documents included in this document). |
| if,
elif |
expr |
Starts
conditional. |
| else |
|
Starts
the 'else' part of the conditional. |
| endif |
|
Ends
conditional.. |
| config |
|
Modifies
various aspects of SSI. |
| |
errmsg |
Default
error message. |
| |
sizefmt |
Format
for size of file. |
| |
timefmt |
Format
for data and time. |
Live Examples Using
SSI Variables (var):
| The
following examples all use the syntax: <!--#echo var="Variable"
--> |
| Variable |
Meaning |
Result |
| HTTP_REFERER |
The
page from which the visitor came |
(none)
|
| HTTP_USER_AGENT |
The
visitor's browser software |
CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
|
| SERVER_SOFTWARE |
The
version of the web server |
Apache
|
| SERVER_NAME |
Your
server name |
www.vaxxine.com
|
| REMOTE_ADDR |
The
remote IP address of the visitor |
38.103.63.16
|
| DOCUMENT_NAME |
The
name of this file |
ssi_info.shtml
|
| DATE_LOCAL |
The
current date (eastern time) |
Monday, 12-May-2008 23:27:41 EDT
|
| DATE_GMT |
The
current date (GMT) |
Tuesday, 13-May-2008 03:27:41 GMT
|
| LAST_MODIFIED |
"Last
modified" date of the current file |
Thursday, 27-Jun-2002 20:41:18 EDT
|
More things you
can do with SSI:
The config
command is allows you to fine tune the output from SSI calls.
For example, you've most likely seen the standard error message:
[an
error occurred while processing this directive]
Well, it's
not exactly useful, especially for your end-users/visitors. So,
if you want instead: [error - contact the site webmaster] instead,
then use the following:
<!--#config
errmsg="[error - contact the site webmaster]"-->
What if you
want to set the format for the file size, or the date, for the
former?:
<!--#config
sizefmt="abbrev"--> will force it to be displayed
rounded to the nearest KB or MB. Also, you can set the argument
"bytes" to set the display as a byte count:
<!--#config sizefmt="bytes"-->
For the time
format...
<!--#config
timefmt="%D (day %j) at %r"-->
This page was last modified on:
<!--#flastmod virtual="ssi_info.shtml"-->
...the output
will be:
This page was last modified on:
06/27/02 (day 178) at 08:41:18 PM
The %D format
inserts the current date in mm/dd/yy format, %j inserts the day
of the year, and %r the current time in hh/mm/ss AM|PM format.
The following table lists other options you have.
| Format |
Value |
Example |
| %a |
Day
of the week abbrev. |
Mon |
| %A |
Day
of the week. |
Monday |
| %b |
Month
name abbrev. |
Jan |
| %B |
Month
name. |
January |
| %d |
Date. |
01
(not 1) |
| %D |
Date
as %m/%d/%y |
01/17/99 |
| %e |
Date |
1 |
| %H |
24-hour
clock hour |
19 |
| %I |
12-hour
clock hour |
07 |
| %J |
Decimal
day of the year |
358 |
| %m |
Month
number |
11 |
| %M |
Minutes |
23 |
| %p |
AM
| PM |
AM |
| %r |
Time
as %I:%M:%S %p |
08:14:23
PM |
| %S |
Seconds |
12 |
| %T |
24
hour time as %H:%M:%S |
23:14:23 |
| %U |
Week
of the year (also %W) |
51 |
| %w |
Day
of the week number |
6 |
| %y |
Year
of the century |
99 |
| %Y |
Year |
1999 |
| %z |
Time
Zone |
PST |
Additional information
and links
For more information
about SSI, see:
|