Odilon Redon's smiling spider

Flow Control with SSI.
author: jim.cerny@unh.edu

last modified on August 03, 1999

This illustrates flow control.

Background.

Flow control refers to the use of SSI conditional commands to dynamically determine what is presented to the Web browser. These commands are if, elif, else, endif. Examples follow.

There are several browser characteristics that are available via environment variables and that are potential candidates for testing to control presentation of material. The following examples make use of testing the browser identity and the browser IP address.

Testing the address.

  • Show the UNHINFO Intranet page if the browser is Alberti, Hopper, or Christa, otherwise show the UNHINFO front page. Note that it is the IP address that is available, not the domain name (text) address. For example, our campus IP addresses all begin "132.177." while the corresponding domain names all end with ".unh.edu". This examples tests for specific system addresses and you could test more generally for either inside or outside of the UNH domain.

    <!--#if expr="$REMOTE_ADDR = /132.177.137.21/" -->
      <a href="http://www.unh.edu/Campus/">Our Intranet page<<a>
    <!--#elif expr="$REMOTE_ADDR = /132.177.137.8/" -->
      <a href="http://www.unh.edu/Campus/">Our Intranet page</a>
    <!--#elif expr="$REMOTE_ADDR = /132.177.137.10/" -->
      <a href="http://www.unh.edu/Campus/">Our Intranet page</a>
    <!--#else -->
      <a href="http://www.unh.edu/">Our front page</a>
    <!--#endif -->
    

Testing the browser.

  • This tests for the browser type, checking for "Mozilla" or "Lynx", otherwise assuming that it might be a search engine spider. This relies on forming an appropriate series of expressions on the conditional statements and the syntax and variable substitution are non-obvious (thanks to Paul Sand for interpretation insights with this example).
    <!--#if expr="$HTTP_USER_AGENT = /^Mozilla/" -->
    <br><b>Mozilla:</b>
      <p>I think people who use Mozilla-compatible browsers
      (Netscape and MSIE) are some of the finest people
      on the Internet.</p>
      <!--#include file="mozilla.html" -->
    <!--#elif expr="$HTTP_USER_AGENT = /^Lynx/" -->
    <br><b>Lynx:</b>
      <p>Anyone can use a graphical Web browser, but it
      shows character when you continue to use a text-only
      browser such as Lynx.</p>
      <!--#include file="lynx.html" -->
    <!--#else -->
    <br><b>Spiders:</b>
      <p>Are you one of those search engine spiders, drifting
      on your parachute silk across the Internet, the way
      Charlotte A. Cavatica's offspring set sail?</p>
      <!--#include file="spider.html" -->
    <!--#endif -->
    

    Spiders:

    Are you one of those search engine spiders, drifting on your parachute silk across the Internet, the way Charlotte A. Cavatica's offspring set sail?

    Are you one of those search engine spiders, drifting on your parachute silk across the Internet, the way Charlotte A. Cavatica's offspring set sail?

Customizing the error message.

This is not really flow control in the sense of if-statements, but it shows how you can provide your own error message for display if an error occurs during the parsing of one of your SSI directives.

  • Default SSI message when trying to include a non-existent file.
    [an error occurred while processing this directive]

  • Default SSI message when trying to parse a bogus directive ("bounce").
    last modified on [an error occurred while processing this directive]

  • Author-supplied SSI message when trying to include a non-existent file.
    <!--#config errmsg="[GEEZ, THE PAGE AUTHOR REALLY MESSED UP.]" -->
    <!--#include file="non-existent.html" -->
    
    [GEEZ, THE PAGE AUTHOR REALLY MESSED UP.]

  • Author-supplied SSI error message when trying to parse a bogus ("bounce") directive.
    <!--#config errmsg="[GEEZ, THE PAGE AUTHOR MESSED UP AGAIN.]" -->
    last modified on <!--#bounce var="LAST_MODIFIED" --> 
    
    last modified on [GEEZ, THE PAGE AUTHOR MESSED UP AGAIN.]


Return to Courses page.