infoCopter.com
retoh's Online Repository for myself and other Web Geeks

home | newsletter | site map

Free Stuff

: links

: Neue Surf Tips

: know-how

: Zitate

: Spam Strike

: HTML Checker!

: Link Checker

: Cartoons



About IC

: friends

: lust und frust

: guestbook

: what's new

Server-side includes
Some useful features you were expecting to run out of the box have to adjusted manually on a RedHat 8.0 full installation.
See also
p-friendly
Home :: Know-how :: Server-side includes


  • Include Page
    <!--#include file="inc1.html"-->

  • Execution:
    <!--#exec cgi="/cgi-local/adc.pl" -->

    • Execution with arguments:
      Depends on the restrictions of your ISP. Some Web servers are not able to parse a call like <!--#exec cgi="... --> because it interprets your arguments as a part of the file name.

      The following version should work in the most of the cases:
      <!--#include virtual="/cgi-local/myscript.pl?myparam=myvalue" -->

  • Date/Time Inserts
    The most commonly used server-side echos involve dates and times. Unless you want to accept your server's default settings, you should precede any such echo statements with a #config statement for timefmt such as the following:

    <!--#config timefmt="%A, %B %d, %Y, at %I:%M %p"-->

    GMT date/time is Friday, August 14, 1998, at 01:38 PM
    LOCAL date/time is Friday, August 14, 1998, at 03:38 PM
    Updated on Wednesday, October 16, 1996, at 09:16 AM

    Date/Time Formatting
    Unix strftime settings are used in the #config timefmt= string. Ordinary characters are copied to the document without conversion, so you can insert "on" or "at" or whatever may be useful.

  • Document Names/Paths
    Other useful echos are as follows:

    This document is <!--#echo var="PATH_TRANSLATED"-->
    This document is /export3/oracle7/ows21/sample/ssi/sstest.html
    Its virtual path is <!--#echo var="DOCUMENT_URI"-->
    Its virtual path is /sample/ssi/sstest.html

    <!--#echo var="DOCUMENT_NAME"--> (12 different varables to this one)

    DOCUMENT_NAME
    DOCUMENT_URI
    DATE_LOCAL
    DATE_GMT
    LAST_MODIFIED QUERY_STRING_UNESCAPED
    SERVER_SOFTWARE
    SERVER_NAME
    REMOTE_HOST
    REMOTE_ADDR
    HTTP_USER_AGENT

  • File Size and Date
    Two other useful directives are #fsize and #flastmod, which allow you to give the size and date of any file on the server-computer rather than just the current document. They work as follows, using file= for relative addressing and virtual= for full path addressing based on your own home directory.

    <!--#config sizefmt="bytes"-->

    File size of 'sstest.html': 6405 bytes
    or

    <!--#config sizefmt="abbrev"-->

    File size of 'sstest.html': 6 Kbytes
    One of the best uses of the #fsize directive is to provide your visitor with the size of any graphics files to be downloaded. This is a tremendous timesaver for you, as an HTML author, if you add and change downloadable images a lot: you never have to look up the sizes and type them in.

  • Browser Used
    It is not of particular interest to the web author him-/herself, but you may reflect back to the person visiting your pages the browser and version, etc., he/she is using to read your pages.
    The code Browser: <!--#echo var="HTTP_USER_AGENT"-->

    produces the following information:

    Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)

  • Host and Server Informtion
    The following line appears at the top of this document:

    Host: <!--#echo var="REMOTE_HOST"--> (<!--#echo var="REMOTE_ADDR"-->) - Server: <!--#echo var="SERVER_NAME"--> (<!--#echo var="SERVER_SOFTWARE"-->)

    and generates the following information:

    Host: proxy.swisscom.com (138.190.1.11) - Server: curie.winf.euv-frankfurt-o.de (Oracle_Web_listener2.1/1.20in2)


This page demonstrates most of WebSite's server-side include capabilities. The file ssi-incl.txt is located in the same directory as this file, accessible via URL as /wsdocs/32demo/ssi-incl.txt. It contains the text This came from a text file and a CRLF. Since the display is in "preformatted (

) format,
line terminators are significant, so there are blank lines after those items. The CGI
program ssicgi.exe simply generates Hello World with no HTTP headers at all. If your CGI
program generates HTTP headers, they will appear in the output. 

First, we set some SSI configuration variables as shown. Note that you can put comments inside the SSI directives after the directive itself:

<!--#config timefmt="%c" use short date/time -->
<!--#config sizefmt="%d bytes"-->
<!--#config errmsg="##ERROR!##"-->


Then we use SSI directives. The directives are shown followed by the substituted output resulting from these directives. :
SSI DIRECTIVE RESULT
---------------------------------------------------------------------------------------------
<!--#daycnt-->5
<!--#totcnt-->386
<!--#lastzero-->07/09/96 08:41:02
<!--#exec cgi="/cgi-win/ssicgi.exe"-->Hello World

<!--#include virtual="/wsdocs/32demo/ssi-incl.txt"-->This came from a text file<br>

<!--#include file="ssi-incl.txt"-->This came from a text file<br>

<!--#fsize virtual="/wsdocs/32demo/ssi-incl.txt"-->28 bytes<br>
<!--#fsize file="ssi-incl.txt"-->28 bytes<br>
<!--#flastmod virtual="/wsdocs/32demo/ssi-incl.txt"-->05/31/96 16:45:40<br>
<!--#flastmod file="ssi-incl.txt"-->05/31/96 16:45:40<br>
<!--#echo var="DOCUMENT_NAME"-->C:\WebSite\wsdocs\32demo\ssi.html-ssi<br>
<!--#echo var="DOCUMENT_URI"-->/wsdocs/32demo/ssi.html-ssi<br>
<!--#echo var="LAST_MODIFIED"-->05/31/96 16:45:40<br>
<!--#echo var="QUERY_STRING"--><br>
<!--#echo var="QUERY_STRING_UNESCAPED"--><br>
<!--#echo var="DATE_LOCAL"-->08/14/98 11:01:22<br>
<!--#echo var="SERVER_SOFTWARE"-->WebSitePro/1.1h<br>
<!--#echo var="SERVER_NAME"-->adminweb.ucis.dal.ca<br>
<!--#echo var="SERVER_PROTOCOL"-->HTTP/1.0<br>
<!--#echo var="REQUEST_METHOD"-->GET<br>
<!--#echo var="REMOTE_HOST"-->proxy.swisscom.com<br>
<!--#echo var="HTTP_ACCEPT"-->image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel,
application/msword, application/vnd.ms-powerpoint, */*<br>
<!--#echo var="HTTP_USER_AGENT"-->Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)<br>
<!--#echo var="REFERER"-->http://www.altavista.digital.com/cgi-bin/query<br>
<!--#echo var="BOGUS"-->##ERROR!##<br>


How to enable Server-side Includes on Apache?

At global context:
# To use server-parsed HTML files
AddType text/html .shtml .shtm .html
AddHandler server-parsed .shtml .shtm .html

At VirtualHost section:
	# server-side includes:
        <Files ~ "\.(html|shtml?)$">
                Options +Includes
        </Files>
Know-How home | Must Read | What's new? | iC Site Map
link search
©1998-2004 infoCopter