howtohead.gif (2988 bytes)

Server Side Includes

This how-to will show you how to some basic server side includes. Remember, in order for Server Side Includes to work, the "*.html" file must be renamed to "*.shtml"

Including a File

With this SSI command, you can reference a text file to be included into your html where the SSI command is placed. To include a file into a web page, use this syntax:

<!--#include file="yourtextfile.txt" -->

Make a text file with plain text or html code and upload it and the "*.shtml" file in ASCII mode. If you are getting thousands of hits per hour, use includes sparingly, because it requires more server processes.

Time and Date

With this SSI command, you can echo the server's current time and date to a web page. Insert this code in the page:

The Local Time is
<!--#echo var="DATE_LOCAL" -->

Rename your html file it "*.shtml".

Last Modifed

This SSI command will check when the file was uploaded to the server or the last time the file was changed. Use the following code:

This page was last modified
<!--#echo var="LAST_MODIFIED" -->

Rename your html file "*.shtml".

Calling a CGI Script

This SSI command will call a specified cgi script, which will run and send the output to the html. This is useful for random image scripts, banner ad scripts, etc. Use this code:

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

Rename your html "*.shtml".

The following SSI commands do not have any practical use for web pages viewed by the public. However, they might be useful for cgi script debugging or cgi script setup programs.

File Path

This SSI command will show the file's server path with respect to your root /html/ directory. Here is the code:

The path to this file is
<!--#echo var="DOCUMENT_URI" -->

More ECHO commands

Here are the values you can put in for the var= in the echo command:

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

AUTH_TYPE client authorization method if any
CONTENT_LENGTH size of input posted from client
CONTENT_TYPE MIME type of content
DATE_GMT The current GMT (greenwich, UK) can be formatted using #config
DATE_LOCAL current time/date, can be formatted using #config
DOCUMENT_NAME document name that was requested
DOCUMENT_URI URL of the document
LAST_MODIFIED document modified date, can be formatted using #config
PAGE_COUNT number of accesses to current document since server was brought on line
REFERRER URL of the document the client came from
REMOTE_ADDR Numeric IP address of the client
REMOTE_HOST domain name of the client (DNS option must be active on server)
REMOTE_USER ID of user, rarely ever found
REQUEST_METHOD HTTP method: GET OR POST
SERVER_NAME server hostname (i.e., www.transonicnet.com)
SERVER_PORT the port used by httpd (usually 80)
SERVER_PROTOCOL Which version of Httpd compliance
SERVER_SOFTWARE The name of the server software, i.e., apache 1.3.1
TOTAL_HITS total pages served by server since brought on line

You can format the date and time commands by inserting the following ssi command before the above ECHO ssi commands:

<!--#config timefmt="%d/%m/%y" -->

Here are the values that can be put in for the timefmt= variable:

%a abbreviated weekday name
%A full weekday name
%b abbreviated month name
%B full month name
%c locale's appropriate date and time representation
%C default date and time format
%d day of month - 01 to 31
%D date as %m/%d/%y
%e day of month - 1 to 31 (single digits are preceded by a blank)
%h abbreviated month name (alias for %b)
%H hour - 00 to 23
%I hour - 01 to 12
%j day of year - 001 to 366
%m month of year - 01 to 12
%M minute - 00 to 59
%n insert a newline character
%p string containing AM or PM
%r time as %I:%M:%S %p
%R time as %H:%M
%S second - 00 to 61
%t insert a tab character
%T time as %H:%M:%S
%U week number of year (Sunday is the first day of the week) - 00 to 53
%w day of week - Sunday=0
%W week number of year (Monday is the first day of the week) - 00 to 53
%x Country-specific date format
%X Country-specific time format
%y year within century - 00 to 99
%Y year as CCYY (4 digits)
%Z timezone name