SSI - Server Side Includes
A small tutorial about Server Side Includes commands by me, Martin Stehle. I hope you find it useful. You can send me email to pewtah@snafu.de. For more information about my person visit my homepage (in german!).
SSI-Commands for Apache: config echo exec flastmod fsize if-elif-else-endif include printenv set
You came from: ">
Your Browser is:
My Server Software is:
Time on my Host is:
To execute SSI commands, your web server must support SSI and your html-files' extension must be '.shtml' or '.ssi'. The server can also set to parse html-files for SSIs.
- config - set some configuration elements
- echo - print variables on screen
- exec - execute CGI-scripts
- flastmod - print last-modified time of a specific file on screen
- fsize - print size of a specific file on screen
- if-elif-else-endif - control output by comparing variables
- include - build in external files
- printenv - print all environment variables on screen
- set - set variables
errmsg
Command: <!--#echo wrong false words -->
Normal Output:: [an error occured while processing this directive]
(Not so nice, eh? So I will set a more natural message as shown in the next line.)
Command: <!--#config errmsg="Unfortunately an error occured. Please inform me via my mail-adress pewtah@snafu.de and I will fix the problem. Thank you in advance." --><!--#echo wrong false words -->
Nice Output:: Unfortunately an error occured. Please inform me via my mail-adress pewtah@snafu.de and I will fix the problem. Thank you in advance.
sizefmt
Command: <!--#config sizefmt="bytes" --><!--#fsize file="index.shtml" -->
Output::
Command: <!--#config sizefmt="abbrev" --><!--#fsize file="index.shtml" -->
Output::
Commands which can be effected by sizefmt
Command: <!--#config timefmt="%d.%m.%Y" --><!--#echo var="DATE_LOCAL" -->
Output::
Command: <!--#config timefmt="%B" --><!--#echo var="DATE_LOCAL" -->
Output::
All Time Formats
- timefmt="%a" :
- timefmt="%A" :
- timefmt="%b" :
- timefmt="%B" :
- timefmt="%c" :
- timefmt="%C" :
- timefmt="%d" :
- timefmt="%D" :
- timefmt="%e" :
- timefmt="%E" :
- timefmt="%f" :
- timefmt="%F" :
- timefmt="%g" :
- timefmt="%G" :
- timefmt="%h" :
- timefmt="%H" :
- timefmt="%i" :
- timefmt="%I" :
- timefmt="%j" :
- timefmt="%J" :
- timefmt="%k" :
- timefmt="%K" :
- timefmt="%l" :
- timefmt="%L" :
- timefmt="%m" :
- timefmt="%M" :
- timefmt="%n" :
- timefmt="%N" :
- timefmt="%o" :
- timefmt="%O" :
- timefmt="%p" :
- timefmt="%P" :
- timefmt="%q" :
- timefmt="%Q" :
- timefmt="%r" :
- timefmt="%R" :
- timefmt="%s" :
- timefmt="%S" :
- timefmt="%t" :
- timefmt="%T" :
- timefmt="%u" :
- timefmt="%U" :
- timefmt="%v" :
- timefmt="%V" :
- timefmt="%w" :
- timefmt="%W" :
- timefmt="%x" :
- timefmt="%X" :
- timefmt="%y" :
- timefmt="%Y" :
- timefmt="%z" :
- timefmt="%Z" :
Set back Time Format
Command: <!--#config timefmt="%A, %d-%b-%Y %T %Z" --><!--#echo var="DATE_LOCAL" -->
Output::
Commands which can be effected by timefmt
- flastmod
- echo var="DATE_LOCAL"
- echo var="DATE_GMT"
- echo var="LAST_MODIFIED"
Overview
Printing Variables
Command (example): <!--#set var="topic" value="Server Side Includes" --><!--#echo var="topic" -->
Output:
Any Environment Variables which can be found via printenv can be accessed this way. E.g.
Command: <!--#echo var="REMOTE_ADDR" --> (the ip of your host)
Output: (the ip of your host)
Overview
With 'exec' you can call CGI-scripts via SSI. E.g. text-only counters, random images or links or text, browser-dependent content etc. It is very powerful by using comparisons.
This feature is also a security hole and can be disabled. Sorry, I cannot offer you an example.
Overview
Command: <!--#config sizefmt="bytes" --><!--#fsize file="index.shtml" -->
Output::
Command: <!--#config sizefmt="abbrev" --><!--#fsize file="index.shtml" -->
Output::
Overview
Command: <!--#flastmod file="index.shtml" -->
Output::
The time format depends on settings via timefmt.
Overview
Command: <!--#include file="somestuff.shtml" -->
Content of somestuff.shtml:
<b>Hello!</b><br>
You came from <!--#echo var="HTTP_REFERER" --> and the URL of this document is <!--#echo var="SCRIPT_URI" -->.
Output:
To access a file in another directory, use 'virtual' instead of 'file'. E.g.:
Command: <!--#include virtual="/the/full/path/to/somestuff.shtml" -->
Overview
Command:
<!--#if expr="1 = 2" -->
1 = 2
<!--#elif expr="1 != 2" -->
1 != 2
<!--#else -->
no match
<!--#endif -->
Output:
1 = 2
1 != 2
no match
Comparison Operators
e is true if e is true or not an empty string
!e is true if e is false or an empty string
e1 && e2 is true if e1 and e2 are true
e1 || e2 is true if e1 or e2 or both are true
e1 = e2 is true if e1 is equal e2
e1 != e2 is true if e1 not is equal e2
Overview
Command: <pre><!--#printenv --><pre>
Output: not called due to security reasons
Each single variable printed by printenv can be also printed with echo.
Overview
Command: <!--#set var="topic" value="Server Side Includes" -->
Variable 'topic' was set to 'Server Side Includes' and can be used e.g. for printing or comparisons.
Overview
By Martin Stehle © , Berlin Germany
Mail: @">@