This topic provides information about server-side include (SSI) commands for the HTTP Server (powered by Apache).
Server-side includes allow you to insert information into CGI programs and HTML documents that the server sends to the client.
HTTP Server (powered by Apache) SSI commands have the following format:
<--#command parameter="value -->
The following describes the SSI commands for HTTP Server (powered by Apache).
This command prints one of the SSI or API variables. Dates are printed using config timefmt. The attributes are:
For example:
<!--#echo encoding="none" -->
This command calls a CGI program. The attributes are:
<!--#exec cgi="/cgi-bin/counter.pgm" -->
This command prints the size of the specified file according to config sizefmt. The attributes are:
<!--#fsize virtual="/include/include.htm" -->
<!--#fsize virtual="/include/include.htm" -->
This command prints the last modification date of the specified file according to config timefmt. The attributes are:
<!--#flastmod file="/include/include.htm" -->
<!--#flastmod virtual="/include/include.htm" -->
This command inserts the text of another file. Included files can be nested. The attributes are:
<!--#include file="/include/include.htm" -->
<!--#include virtual="/include/include.htm" -->
This command prints all existing environment variables and their values. There are no attributes. For example:
<!--#printenv -->
This command sets the value of an environment variable. The attributes are:
See Environment variables on HTTP Server for a list of environment variables.
<!--#set var="var1" value="yes" -->
If you want to insert a special character in a string, precede it with a \. For example:
<!--#set var="var1" value="\$Date_GMT" -->
There are four conditional or flow control commands. The if command tests a value. If the value is true, then processing continues with the next line. If the value is not true then processing continues with an elif, else, or endif command. The elif and else commands are optional. The if and elif commands have a parameter of expr. The expr parameter contains the test condition. An endif command is required for every if command. For example:
<!--#if expr="$USER_AGENT = /MSIE/" --> <P>You are using Internet Explorer.</P> <!--#elif expr="$USER_AGENT = /Mozilla/" --> <P>You are using Netscape.</P> <!--#else --> <P>You are not using Internet Explorer or Netscape.</P> <!--#endif -->
The expr parameter can have one of the following forms:
Condition | Comments |
---|---|
string | True if the string is not empty |
string1 = string2 (equal) | Compare string1 with string2. If string2 has the form /string/, then it is compared as a regular expression. See Regular expression notation for HTTP Server for more information. |
string1 != string2 (not equal) | |
string1 < string2 (less than) | |
string1 <= string2 (less than or equal to) | |
string1 > string2 (greater than) | |
string1 > = string2 (greater than or equal to) | |
( test_condition ) | True if test_condition is true. |
!test_condition | True if test_condition is false. |
Test_condition1 && test_condition2 | True if both test_condition1 and test_condition2 are true. |
Test_condition1 || test_condition2 | True if either test_condition1 or test_condition2 are true. |
Values can be supplied in the following ways:
<!--#config timefmt="%b%d%y" -->
<!--#ifexpr="$a=\$test" -->
<!--#set var="ABC" value="${REMOTE_HOST}_${REQUEST_METHOD}" -->
If REMOTE_HOST is equal to X and REQUEST_METHOD is equal to Y, then $ABC is equal to X_Y.
Server-side includes look for the variable, echoes where the variable is found, and proceeds with the function. You can have multiple variable references. When server-side includes encounter a variable reference inside a server-side include directive, it attempts to resolve it on the server side. The following example escapes the & so that server-side includes do not recognize it as a variable. In the second line of the example, the variable "&index" is a server-side variable and is used to construct the variable name "var1". The variable ê is a client side variable, so the & is escaped to create the value ":frêd" or "fred" with a circumflex over the e.
<!--#set var="index" value="1" --> <!--#set var+"var&index;" value+"fr\êd" --> <!--#echo var="var1" -->
The following characters can be escaped. Escape variables must be preceded with a backslash (\).
Escape variable | Meaning |
---|---|
\a | Alert (bell) |
\b | Backslash |
\f | Form feed (new page) |
\n | New line |
\r | Carriage return |
\t | Vertical tab |
\v | Vertical tab |
\' | Single quote mark |
\'' | Double quote mark |
\? | Question mark |
\\ | Backslash |
\- | Hyphen |
\. | Period |
\& | Ampersand |