Some SSI examples

A common mistake users make when first attempting to use SSI is to include a space between the <!-- and the #, perhaps because the construct resembles an HTML comment. It won't work with a space before the command - it's simply a comment then.

List of [a-e]*.shtml files in this directory: <!--#exec cmd="ls -l [a-e]*.shtml" --> Note that SSI exec is disabled for users on this site, so this directive will produce an error. The directive is enabled for the rest of this site (see linuxsig/test.shtml) - just not for users' personal pages. Attempting to do so will result in an error, as seen below.


Display the current time using the default date format.
The time in Ohio is <!--#echo var="DATE_LOCAL" -->.
The time in Ohio is Saturday, 04-Feb-2012 02:45:08 PST.

Use another time format for file modified date. <!--#config timefmt="%l:%M:%S %P, %a, %b. %d, %Y" -->
This file was last modified <!--#echo var="LAST_MODIFIED" -->.
This file was last modified 6:23:31 pm, Sun, Oct. 07, 2007.

An alternate way is <!--#flastmod file="test.shtml" -->
6:23:31 pm, Sun, Oct. 07, 2007

The name of this file is <!--#echo var="DOCUMENT_NAME" -->
The name of this file is test.shtml

This file size is <!--#fsize file="test.shtml" -->
This file size is 4.2K

The DOCUMENT_URI of this file is <!--#echo var="DOCUMENT_URI" -->
The DOCUMENT_URI of this file is /~lundyd/test.shtml

Show something about your browser:
<!--#if expr="${HTTP_USER_AGENT} = /MSIE/" -->
    You are using some version of Microsoft IE Browser Be careful!
<!--#else -->
    Thank you for not using a Microsoft IE Browser
<!--#endif -->
Your browser identifies itself as <!--#echo var="HTTP_USER_AGENT" -->.

Result: Thank you for not using a Microsoft IE Browser
Your browser identifies itself as CCBot/1.0 (+http://www.commoncrawl.org/bot.html).

Several variables are made available to parsed documents. In addition to the CGI variable set, the following variables are made available:

To learn more about SSI, see this very complete tutorial at LearnThat.com.

<!--#include virtual=".include_brief_footer.shtml"-->

   
[Powered by RedHat Linux]

This page was last modified Sun, Oct 07 2007 06:23 pm PDT.

Contact: Dave Lundy