Products
 Services
 Online Sales
 News
 Training
 Tech Support
 Reference Library
 Software Library
 Company Info
 Employment
 Site Map
 Email Us
Search Search

.
Information Technologies
Empowering Business Through Technologies
SSI - Server Side Includes
SSI are a very useful tool for the Web development. SSI can provide simple dynamic content without the use of CGI or ASP. SSI allow making site-wide changes to a domain by updating only the include file(s). In addition, SSI syntax has simple branching logic allowing you to tailor your Web pages to the environment in which they are displayed.

The following echo commands insert the contents of a HTTP environment variable into the response stream being sent to the client replacing the ssi directive.

CODEPURPOSE OF CODEOUTPUT
ALL_HTTPAll the name/value pairs for HTTP environment variables.(none)
QUERY_STRING_UNESCAPEDholds unaltered query string with all shell metacharacters escaped with a "\"(none)
AUTH_PASSWORDThe password provided by the user to the server if this page denied anonymous access and the client authenticated using the Basic method.(none)
AUTH_TYPEclient authorization method if any(none)
AUTH_USERThe username provided by the user to the server if this page denied anonymous access under both Basic and NTLM methods.(none)
CONTENT_LENGTHThe number of bytes of data sent as a POST to the server.(none)
CONTENT_TYPEThe MIME type of the data sent as a POST to the server.(none)
DATE_GMTThe current GMT (greenwich, UK) can be formatted using #configSunday, 22-Oct-2017 22:53:09 GMT
DATE_LOCALcurrent time/date, can be formatted using #configSunday, 22-Oct-2017 15:53:09 PDT
DOCUMENT_NAMEdocument name that was requested - holds the current filenamessi.shtml
DOCUMENT_ROOTThe root directory of the site./home/infotech/sbotte/info-techs.com/data
DOCUMENT_URIURL of the document -holds path of file from server root to filename/ssi.shtml
GATEWAY_INTERFACEThe type of gateway used to handle the request, e.g. CGI/1.1CGI/1.1
HTTP_ACCEPTA comma-delimited list of MIME types that the client application has notified the server that it can accept.text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_CHARSETThe Servers accepted character set.(none)
HTTP_ACCEPT_ENCODINGA comma-delimited list of MIME types that the client application has notified the server that it can accept.x-gzip, gzip, deflate
HTTP_ACCEPT_LANGUAGEThe LANGUAGE types the server is requested to accept as defined in the HTTP header and typically used for content negotiation.(none)
HTTP_CACHE_CONTROLCache age(none)
HTTP_CONNECTIONThe type of connection as defined in the HTTP header.(none)
HTTP_COOKIECookie(none)
HTTP_DNTDNT(none)
HTTP_HOSTThe type of connection as defined in the HTTP header.info-techs.com
HTTP_REFERERThe URL of the page that made the request.(none)
HTTP_USER_AGENTThe browser id or user-agent string identifying the browser.CCBot/2.0 (http://commoncrawl.org/faq/)
LAST_MODIFIEDThe document modified date, can be formatted using #configWednesday, 09-Nov-2011 13:05:13 PST
PAGE_COUNTNumber of accesses to current document since server was brought on line(none)
PATHThe path to the current document/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
PATH_INFOThe full virtual path and filename of the document requested, in relation to the root folder of the web site.(none)
PATH_TRANSLATEDThe full physical path and filename of the document requested.(none)
QUERY_STRINGThe value of any query string appended to the URL of the document requested, after translation from the URL-encoded format.
QUERY_STRING_UNESCAPEDThe value of any query string appended to the URL of the document requested, before translation from the URL-encoded format.(none)
REFERRERThe URL of the document the viewer came from.(none)
REMOTE_ADDRNumeric IP address of the client54.80.209.254
REMOTE_HOSTDomain name of the client (DNS option must be active on server)(none)
REMOTE_PORTThe port number used by the remote host when making this request.49018
REMOTE_USERID of user, rarely ever found(none)
REQUEST_METHODHTTP method: the method used when requesting the page, 'Get' 'Head' or 'Post'GET
REQUEST_URIThe URI of the requested page, relevant to the document root./ssi.shtml
SCRIPT_NAMEThe full virtual path and filename of the document requested in relation to the root folder of the web site./ssi.shtml
SCRIPT_FILENAMEThe full virtual path and filename of the document requested in relation to the root folder of the web site./home/infotech/sbotte/info-techs.com/data/ssi.shtml
SERVER_ADDRThe IP address of the server for this URL.108.38.249.194
SERVER_ADMINThe administrators email address for this server.scott@info-tech.com
SERVER_NAMEThe network name or URL host name of the server that received the request.info-techs.com
SERVER_PORTThe port used by httpd (usually 80)80
SERVER_PORT_SECUREThe port number if the request was over a secure protocol.(none)
SERVER_PROTOCOLThe HTTP protocol that the request was passed under, HTTP/1.1HTTP/1.0
SERVER_SIGNATUREThe HTML string that may be embedded in the page to identify this host.
SERVER_SOFTWAREThe name/version of the web server.Apache/2.4.27 (Unix) OpenSSL/1.0.2h PHP/5.6.31
TOTAL_HITSThe total pages served by server since brought on line(none)
URLThe complete URL that the user specified when requesting the document.(none)
USER_NAMEThe current user name.sbotte
The original purpose of SSI was to be able to "include" or copy files into an HTML document. This is one of the truely powerful function SSI can perform, allowing the server to assemble HTML documents from separate include files into a single HTML page which is displayed to the user.

As an example, on this server there exist a file, header.txt, which is in the same directory as the this page (ssi.shtml). The header.txt file contains the following text:
<center>This is the text at the top of the HTML page called a header.</center>
By using SSI we can include that text in the body of this (or any SSI enabled .shtml) page by using the include file directive:
<!--#include file="header.txt" -->
This would yield the following output:
This is the text at the top of the HTML page called a header.
Note that the browser has interpreted the HTML code (the center commnad) as well displaying the text. To see this, view this pages source code.

The above example assumes that the SSI include file is in the same directory as the HTML file calling it. If we wanted to put all of the include files into a folder such as /includes, we would have to use the include virtual directive:

<!--#include virtual="/includes/header.txt" -->
This is the text at the top of the HTML page called a header.

The SSI include directive can be used as a substitute for the rather complected Cascading Style Sheets (CSS), which currently is not well supported across various browsers, ASP, CGI, PERL, or PHP, allowing dynamic web page content to be assembled from separate files. As an example, this could be used change the theme for a domain. Setting up a Christmas, New Years, 4th of July, etc. set of SSI files which change the background colors and images for all web pages could be automated by using cron to copy the necessary files into the /includes folder.
Use the following code to create a "Back Button" link. This will take the viewer back to the page they came here from. Code:
<A HREF="<!--#echo var="HTTP_REFERER"-->">BACK BUTTON</A>
BACK BUTTON
Files size can also be displayed using the fsize directive. The code:
<!--#config sizefmt="bytes" --><!--#fsize file="ssi.shtml" --> bytes
yields the size of this page: 20,544 bytes
The date and time output for:
  • DATE_GMT
  • DATE_LOCAL
  • LAST_MODIFIED
can be formatted using the below listed SSI variables. For example, the standard output for <!--#echo var="DATE_LOCAL" --> looks like:
Sunday, 22-Oct-2017 15:53:09 PDT
If we place a format code modifier in front of the directive such as <!--#config timefmt="%m/%d/%y" --><!--#echo var="DATE_LOCAL" --> the modified output yields:
10/22/17
%aAbbreviated weekday nameSun
%AFull weekday nameSunday
%bAbbreviated month nameOct
%BFull month nameOctober
%cLocale's appropriate date and timeSun Oct 22 15:53:09 2017
%CDefault date and time format20
%dDay of month - 01 to 3122
%DDate as %m/%d/%y10/22/17
%eDay of month - 1 to 3122
%HHour - 00 to 2315
%IHour - 01 to 1203
%jDay of year - 001 to 366295
%mMonth of year - 01 to 1210
%MMinute - 00 to 5953
%nInsert a newline characterLine beforeMiddle Line after
%pString containing AM or PMPM
%rTime as %I:%M:%S %p03:53:09 PM
%RTime as %H:%M15:53
%SSecond - 00 to 5909
%tInsert a tab characterBefore TabMiddle After Tab
%TTime as %H:%M:%S15:53:09
%UWeek number of year (Sunday is the first day of the week) - 00 to 5343
%wDay of week - Sunday=00
%WWeek number of year (Monday is the first day of the week) - 00 to 5342
%xCountry-specific date format10/22/17
%XCurrent time formatted for servers locale15:53:09
%yYear within century - 00 to 9917
%YYear as CCYY (4 digits)2017
%zTime zone name/abbrev of servers time zone.-0700
%ZTime zone name/abbrev of servers time zone.PDT
%+The national representation of the date and timeSun Oct 22 15:53:09 PDT 2017
%%A percent character.%
There are two common pitfalls when trying to use SSI.
  1. People usually put a space between the <!-- and the #. If you add this space your SSI won't work.
  2. People forget that SSI depend on both Web server type and configuration. Remember, if your server is configured to only parse SSI in files with a .shtml extension and you save your HTML page with include directives as .html, your SSI won't be parsed by the server and consequently won't work.
  3. Some webservers require that the variable name be CAPITALIZED.



Page last modified on: Wednesday November 9, 2011 at 13:05 PST