×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SSI (Server Side Includes)

What can I do with SSI? by Wullie
Posted: 30 May 02 (Edited 2 Aug 03)

This explains what you can do with SSI on your server.

SSI are directives that are placed in HTML pages, and are parsed by the server while the pages are being served.

SSI directives are of the following syntax:

<!--#element attribute=value attribute=value -->

The most noticable thing you can do with SSI is to include other files into a page. This file can be anything from a basic text file to a full blown perl script.

To include another file into a page then you need to use different directives depending on the file you are including.

For a CGI file, you would use one of the following syntax:

<!--#include virtual="/cgi-bin/script.pl" -->

Or

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


For a basic text or html file, you can use on of the following:

<!--#include virtual="/myfile.html" -->

Or

<!--#include file="/myfile.html" -->



Some other things that can be done with SSI are as follows:


Include the date and time on your page:

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

Now, to take this a little further, you can specify the format that the time is displayed in by using the following:

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


To include the date a page was last modified, use the following:

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

To display on one page the time another file was modified, use the following:

<!--#flastmod file="index.html" -->

You can also use the timefmt command with this directive.


If there is a problem and the SSI cannot execute, the following error is displayed to the browser.

[an error occurred while processing this directive]

To change the error that is returned, use the following syntax:

<!--#config errmsg="[This is the error message here]" -->


If you wanted to run shell commands then you could use the following directives, this example would place a directory listing on your page.

On Unix,
        <pre>
        <!--#exec cmd="ls" -->
        </pre>

or, on Windows

        <pre>
        <!--#exec cmd="dir" -->
        </pre>


Another useful SSI directive is the abilty to specify variables.

<!--#set var="myname" value="Wullie" -->

<!--#set var="modified" value="$LAST_MODIFIED" -->


mod_include also provides an if, elif, else, endif structure for building conditional statements.

<!--#if expr="my_test" -->
    <!--#elif expr="my_test" -->
    <!--#else -->
    <!--#endif -->


You can use this to create server-side browser checks and then display different content based on the browser.


<!--#if expr="${HTTP_USER_AGENT} = /WebTV/" -->
 <!--#set var="brtype" value="webtv" -->
 <!--#elif expr="${HTTP_USER_AGENT} = /MSIE 5/" -->
  <!--#set var="brtype" value="msie5" -->
 <!--#elif expr="${HTTP_USER_AGENT} = /MSIE 4/" -->
  <!--#set var="brtype" value="msie4" -->
  <!--#elif expr="${HTTP_USER_AGENT} = /MSIE 3/" -->
   <!--#set var="brtype" value="msie3" -->
   <!--#elif expr="${HTTP_USER_AGENT} = /MSIE 2/" -->
    <!--#set var="brtype" value="msie2" -->
    <!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/4/ && $brtype !=/msie/" -->
     <!--#set var="brtype" value="netscape4" -->
     <!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/3/ && $brtype !=/msie/" -->
      <!--#set var="brtype" value="netscape3" -->
      <!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/2/ && $brtype !=/msie/" -->
       <!--#set var="brtype" value="netscape3" -->
      <!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/1/ && $brtype !=/msie/" -->
       <!--#set var="brtype" value="netscape2" -->
    <!--#else -->
     <!--#set var="brtype" value="unknown" -->
<!--#endif -->
<!--#include file="$brtype.txt"-->




<!--#if expr="${HTTP_USER_AGENT} = /Mac/" -->
        <!--#set var="platform" value="mac" -->
        <!--#else -->
        <!--#endif -->

<!--#if expr="${HTTP_USER_AGENT} = /MSIE/ && $platform =/mac/" -->
MAC IE
<!--#elif expr="$platform =/mac/" -->
MAC, NOT IE
        <!--#else -->   
NOT MAC
        <!--#endif -->


SSI is certainly not a replacement for CGI, or other technologies used for generating dynamic web pages, but it is a great way to add small amounts of dynamic content to pages, without doing a lot of extra work.

http://httpd.apache.org/docs/howto/ssi.html
http://www.bignosebird.com/ssi.shtml
FAQ65-3699
FAQ65-3700
FAQ253-3309

Hope this helps

Wullie

sales@freshlookdesign.co.uk
www.freshlookdesign.co.uk

Back to Linux (server) FAQ Index
Back to Linux (server) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close