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: (none)
Your Browser is: CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
My Server Software is: Apache/2.0.63 (FreeBSD)
Time on my Host is: Tuesday, 09-Feb-2010 12:26:59 CET
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:: 14,455
Command: <!--#config sizefmt="abbrev" --><!--#fsize file="index.shtml" -->
Output:: 14K
Commands which can be effected by sizefmt
Command: <!--#config timefmt="%d.%m.%Y" --><!--#echo var="DATE_LOCAL" -->
Output:: 09.02.2010
Command: <!--#config timefmt="%B" --><!--#echo var="DATE_LOCAL" -->
Output:: February
All Time Formats
- timefmt="%a" : Tue
- timefmt="%A" : Tuesday
- timefmt="%b" : Feb
- timefmt="%B" : February
- timefmt="%c" : Tue Feb 9 12:26:59 2010
- timefmt="%C" : 20
- timefmt="%d" : 09
- timefmt="%D" : 02/09/10
- timefmt="%e" : 9
- timefmt="%E" : E
- timefmt="%f" : f
- timefmt="%F" : 2010-02-09
- timefmt="%g" : 10
- timefmt="%G" : 2010
- timefmt="%h" : Feb
- timefmt="%H" : 12
- timefmt="%i" : i
- timefmt="%I" : 12
- timefmt="%j" : 040
- timefmt="%J" : J
- timefmt="%k" : 12
- timefmt="%K" : K
- timefmt="%l" : 12
- timefmt="%L" : L
- timefmt="%m" : 02
- timefmt="%M" : 26
- timefmt="%n" :
- timefmt="%N" : N
- timefmt="%o" : o
- timefmt="%O" : O
- timefmt="%p" : PM
- timefmt="%P" : P
- timefmt="%q" : q
- timefmt="%Q" : Q
- timefmt="%r" : 12:26:59 PM
- timefmt="%R" : 12:26
- timefmt="%s" : 1265714819
- timefmt="%S" : 59
- timefmt="%t" :
- timefmt="%T" : 12:26:59
- timefmt="%u" : 2
- timefmt="%U" : 06
- timefmt="%v" : 9-Feb-2010
- timefmt="%V" : 06
- timefmt="%w" : 2
- timefmt="%W" : 06
- timefmt="%x" : 02/09/10
- timefmt="%X" : 12:26:59
- timefmt="%y" : 10
- timefmt="%Y" : 2010
- timefmt="%z" : +0100
- timefmt="%Z" : CET
Set back Time Format
Command: <!--#config timefmt="%A, %d-%b-%Y %T %Z" --><!--#echo var="DATE_LOCAL" -->
Output:: Tuesday, 09-Feb-2010 12:26:59 CET
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: Server Side Includes
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: 38.107.191.84 (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:: 14,455
Command: <!--#config sizefmt="abbrev" --><!--#fsize file="index.shtml" -->
Output:: 14K
Overview
Command: <!--#flastmod file="index.shtml" -->
Output:: Tuesday, 23-May-2000 01:42:59 CEST
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: Hello!
You came from (none) and the URL of this document is http://home.snafu.de/pewtah/ssi/index.shtml.
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
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:
UNIQUE_ID=Mjcb5VQX-pYAASIehH8AAAAQ
SCRIPT_URL=/pewtah/ssi/index.shtml
SCRIPT_URI=http://home.snafu.de/pewtah/ssi/index.shtml
VISP_DOMAIN=snafu.de
VISP_USER=pewtah
HTTP_X_CC_ID=ccc02-01
HTTP_HOST=home.snafu.de
HTTP_USER_AGENT=CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
HTTP_ACCEPT=text/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5
HTTP_ACCEPT_ENCODING=gzip
HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_CONNECTION=close
HTTP_CACHE_CONTROL=no-cache
HTTP_PRAGMA=no-cache
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/root/bin
SERVER_SIGNATURE=
SERVER_SOFTWARE=Apache/2.0.63 (FreeBSD)
SERVER_NAME=home.snafu.de
SERVER_ADDR=10.150.10.19
SERVER_PORT=80
REMOTE_ADDR=38.107.191.84
DOCUMENT_ROOT=/dm/users/reseller/snafu.de/htdocs
SERVER_ADMIN=webmaster@snafu.de
SCRIPT_FILENAME=/dm/users/sn/snafu.de/pe/pewtah/public_html/ssi/index.shtml
REMOTE_PORT=42266
GATEWAY_INTERFACE=CGI/1.1
SERVER_PROTOCOL=HTTP/1.1
REQUEST_METHOD=GET
QUERY_STRING=
REQUEST_URI=/pewtah/ssi/index.shtml
SCRIPT_NAME=/pewtah/ssi/index.shtml
DATE_LOCAL=Tuesday, 09-Feb-2010 12:26:59 CET
DATE_GMT=Tuesday, 09-Feb-2010 11:26:59 GMT
LAST_MODIFIED=Tuesday, 23-May-2000 01:42:59 CEST
DOCUMENT_URI=/pewtah/ssi/index.shtml
USER_NAME=pewtah_snafu.de
DOCUMENT_NAME=index.shtml
topic=Server Side Includes
Each single variable can be 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 © 2010, Berlin Germany
Mail: pewtah@snafu.de