SSI (Server Side Includes) and SHTML Setup

By using SSI, you can utilize dynamic features for your web site.  For example, by placing the following code...

<!--#echo var="DATE_LOCAL" -->

...inside your HTML and naming your HTML file with the extension .shtml, when the .shtml file is called via a browser, the server will scan (parse) the HTML code for special commands.  The command above generated the following date when you "called" for this web page via your browser...

Sunday, 25-Feb-2018 11:31:55 CST

We can easily change how the date looks such as...

<!--#config timefmt="%A, %B %d %Y" --> <!--#echo var="DATE_LOCAL" -->

...results in...

Sunday, February 25 2018

So what commands are available regarding the date?  Here they are...

Display Full Display Abbreviated
Code Results Example Code Results Example
%B Month February %b Month Feb
%A Weekday  Sunday %a Weekday Sun
%Y Year 2018 %y Year 18
%D Date 02/25/18 %d Day of the Month 25
Other Customizations
%H Current Hour
11 %I Current Hour
%M Current Minutes
31 %S Current Seconds
%p AM or PM AM %Z Time Zone CST
%m Month (1-12) 02      
Time Saving Commands
%R Time
(24 hours)
Displayed as...
11:31 %r Time
(12 hours)
Displayed as...
11:31:55 AM
%T Time
(24 hours)
Displayed as...


Date and Time Examples...
<!--#config timefmt="%A %B %d %Y" --> <!--#echo var="DATE_LOCAL" --> Sunday February 25 2018
<!--#config timefmt="%I %p" --> <!--#echo var="DATE_LOCAL" --> 11 AM
<!--#config timefmt="%B %d" --> <!--#echo var="DATE_LOCAL" --> February 25


Additional SSI Commands
Web Page Related...
<!--#echo var="HTTP_REFERER" --> The page that brought you here was...
<!--#echo var="REMOTE_ADDR" --> Your IP address is...
<!--#echo var="DOCUMENT_NAME" --> The name of the web page you are currently viewing is...
<!--#fsize file="ssi_and_shtml.shtml" --> The size of the web page you are currently viewing is...
<!--#flastmod file="ssi_and_shtml.shtml" --> The page you are currently viewing was last modified on...
  Tuesday, 24-Jan-2006 10:16:26 CST
Date Related...
<!--#echo var="DATE_LOCAL" --> Current Date and Time...
  Sunday, 25-Feb-2018 11:31:55 CST
<!--#echo var="DATE_GMT" --> Current GMT Date and Time...
  Sunday, 25-Feb-2018 17:31:55 GMT
<!--#include file="folder/name.txt" --> You can include a text file or some other file to be displayed.  Sunday, 25-Feb-2018 11:31:55 CST

Running a CGI or PL program from .shtml

If you call or run a CGI or PL program from an HTML document in a statement such as...

<!--#exec cgi="/cgi-bin/counter/counter.cgi" -->

...make sure you name the HTML file with the extension ".shtml" or it will not run the requested CGI program.

Because the server scans the SHTML file for special codes, this scan will result in two side effects.  1. A pause in display while the server scans the HTML file and performs any requested actions it finds embedded within the HTML, and 2. More server resources are naturally required to parse a .shtml page.  Keep this in mind as to not overuse .shtml pages on a busy web site.

Common Questions About SSI (SHTML)

PROBLEM:  When I view the .shtml page in the browser, and then view the HTML source code, the SSI command is still there and the expected results aren't displayed.

WHAT IS HAPPENING:  The server does not recognize the SSI command.

SOLUTION:  For all SSI commands, make sure there is ONE SPACE before the closing symbol --> as follows...
<!--#exec cgi="/cgi-bin/counter/counter.cgi" -->

PROBLEM:  The page shows the following...
[an error occurred while processing this directive]

WHAT IS HAPPENING:  The server recognizes the SSI command, however, there is an error in the SSI command and the server doesn't know what to do.

SOLUTION:  Make sure the path and filename in the SSI command is correct.

PROBLEM:  When I view the .shtml page in the browser, and then view the HTML source code, the SSI is no longer there, but the are no results displayed in its place.

WHAT IS HAPPENING:  The server has recognized the SSI command and has attempted to run the CGI or PL program.  However, there is either an error in the CGI program, or no output is defined in the CGI program.



Please note that scripts can enter infinite loops and cause problems for any server.  Please edit scripts with care!

For additional assistance visit our CGI-bin Applications Page.

[Manual Index]


Copyright 2000-2006 All Rights Reserved. Terms and Conditions of Use and Privacy Policy. - Your Success Is Our Success