Advanced Features

These are available in the Apache web server, versions 1.2 and above. Some others may also support it for compatibility, but that's up to you to experiment with.


The printenv command displays all of the system variables and their values.
<--#printenv -->


This allows you to set the value of a variable, and is useful in confunction with the if/then/else directives.

<--#set var="varname" value="data" -->

If / Then / Else

These allow you to select different things to display, base on the contents of the various variables. For example, you might want to do something different for users whose HTTP_USER_AGENT contains "MSIE" (i.e. Internet Explorer Users) than for those who use Netscape. Or maybe you could use this in a template file for a collapsable menu, and expand the appropriate section by using the set command within the parent file...
    <!--#if expr="condition" -->
     (this is displayed if first condition is met)
    <!--#elif expr="condition" -->
     (otherwise this is displayed if second condition is met)
    <!--#else -->
     (if neither condition is met, this is displayed)
    <!--#endif -->
The condition is a comparison between two strings, using the operators =, != (not equals), <, <=, >, and >=

Compound conditions can be made by using ((Condition1) && (Condition2)) (AND), ((Condition1) || (Condition2)) (OR), (!(Condition1)) (NOT), and any combination of these. The parentheses are not always required, but do no harm and improve readability.

For information on how to compare the contents of variables, see the next section.

Variable Substitution

To use a variable's data as the value to be displayed or compared, or the file to be accessed, simply enter the variable name with a $ sign in front of it.

Example :
  <--#if expr="$varname = 'test'" -->
If the variable varname is equal to the string "test", then the if statement will evaluate to true. This technique can be used for almost any of the SSI commands.

  • To isolate the variable name from other data, it may be enclosed in braces : ${HTTP_USER_AGENT}
  • If the $ sign itself is required, use the backslash character in front of it : \$5.00
(C)opyright, Geoff Knagge.
Continued use of this site indicates your agreement to the Conditions of use and Privacy Policy.