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.

List of [a-e]*.shtml & test files in this directory: <!--#exec cmd="ls -l [a-e]*.shtml test*" -->

-rw-rw-r--    1 www      www         16237 Sep 19  2006 bios.shtml
-rw-rw-r--    1 lundyd   www         74064 Jun  3  2006 ev.shtml
-rw-rw-r--    1 lundyd   www        106208 Jun  3  2006 events-bak.shtml
-rw-rw-r--    1 www      www         87441 Jun  3  2006 events.bak.shtml
-rw-rw-r--    1 lundyd   www         33869 Jan  6 19:02 events.shtml
-rw-r--r--    1 lundyd   www          4529 Sep 26  2006 test.shtml
-rw-r-----    1 lundyd   www         14332 Sep 27  2006 test2.shtml
-rw-r--r--    1 lundyd   www            69 Oct  1  2004 test2.ssi
-rw-r--r--    1 lundyd   www            69 Oct  1  2004 test3.ssi

Display the current time using the default date format.
The time in Ohio is <!--#echo var="DATE_LOCAL" -->.
The time in Ohio is Thu, 08 Jan 2009 08:25:50 -0500.

Display the current date using date format Day, Month day of month, Year.
<!--#config timefmt="%A, %B %d, %Y" -->
The date in Ohio is <!--#echo var="DATE_LOCAL" -->.
The date in Ohio is Thursday, January 08, 2009.

Specify a different time format. <!--#config timefmt="%a, %b %d %I:%M:%S %P %Z" -->
The time in Ohio is <!--#echo var="DATE_LOCAL" -->.
The time in Ohio is Thu, Jan 08 08:25:50 am EST.

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 2:30:29 pm, Tue, Sep. 26, 2006.

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 -->
Result: Thank you for not using a Microsoft IE Browser

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

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

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

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

  • DOCUMENT_NAME: The current filename.
  • DOCUMENT_URI: The virtual path to this document (eg. /docs/foo.shtml).
  • QUERY_STRING_UNESCAPED: The unescaped version of any search query the client sent, with all shell-special characters escaped with \.
  • DATE_LOCAL: The current date, local time zone. Subject to the timefmt parameter to the config command.
  • DATE_GMT: Same as DATE_LOCAL but in Greenwich mean time.
  • LAST_MODIFIED: The last modification date of the current document. Subject to timefmt like the others.

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

Include a standard footer in each page... <!--#include virtual="include/footer.shtml"-->


Search the contents of all the publicly available web pages at www.dma.org/linuxsig/ or archives of our mailing list.
Google look in

Subscribe to our Linux-SIG mailing list for occasional technical correspondence regarding Linux, Unix, & Open Source Software at the Linux-SIG Info Page & read our archives. Check out our other Special Interest Group (SIG) mailing lists here.
Users Group Contact: Grant Root 937-274-3378, Dave Lundy 937-426-1132 9 am–10 pm, Gary Turner 937-313-BITS DLUG-contact
Web Site Contact: For questions about, or suggestions for our web site, please write to DLUG-web

  DLUG | DMA | Events | Facebook | Feedback | Files | Install | Links | People | Upload  
[Powered by RedHat Linux]
Thanks to Stephen Sullivan, at SPS Interactive Design,
for our new logo and site design suggestions.
Site maintained by DLUG web team
This page was last modified 02:30 pm Tue, Sep 26, 2006 EDT.
Valid HTML 4.01!