Server-side include commands for HTTP Server

This topic provides information about server-side include (SSI) commands for the HTTP Server (powered by Apache).

Important: Information for this topic supports the latest PTF levels for HTTP Server for i5/OS . It is recommended that you install the latest PTFs to upgrade to the latest level of the HTTP Server for i5/OS. Some of the topics documented here are not available prior to this update. See http://www.ibm.com/servers/eserver/iseries/software/http/services/service.htm Link outside Information Center for more information.

Server-side includes allow you to insert information into CGI programs and HTML documents that the server sends to the client.

Server-side include commands for HTTP Server (powered by Apache)

HTTP Server (powered by Apache) SSI commands have the following format:

<--#command parameter="value -->
Note: There is a space before -->.

The following describes the SSI commands for HTTP Server (powered by Apache).

echo

This command prints one of the SSI or API variables. Dates are printed using config timefmt. The attributes are:

var
Specifies an environment variable name or CGI environment variable name.
See the Environment variables on HTTP Server topic for a list of environment variables.

For example:

<!--#echo var="DATE_GMT" -->
encoding
Specifies how the server encodes special characters contained in the variable. If set to none, no encoding is done. If set to url, then URL encoding (or %-encoding) is performed. If set to the default of entity, then entity encoding is performed.

For example:

<!--#echo encoding="none" -->

exec

This command calls a CGI program. The attributes are:

cgi
Specifies the relative path and file name. For example:
<!--#exec cgi="/cgi-bin/counter.pgm" -->

fsize

This command prints the size of the specified file according to config sizefmt. The attributes are:

file
Specifies the relative path and file name. For example:
<!--#fsize virtual="/include/include.htm" -->
virtual
Specifies the relative path and file name using URL encoding. For example:
<!--#fsize virtual="/include/include.htm" -->

flastmod

This command prints the last modification date of the specified file according to config timefmt. The attributes are:

file
Specifies the relative path and file name. For example:
<!--#flastmod file="/include/include.htm" -->
virtual
Specifies the relative path and file name using URL encoding. For example:
<!--#flastmod virtual="/include/include.htm" -->

global

This command is the same as the set command.

include

This command inserts the text of another file. Included files can be nested. The attributes are:

file
Specifies the relative path and file name. For example:
<!--#include file="/include/include.htm" -->
virtual
Specifies the relative path and file name using URL encoding. For example:
<!--#include virtual="/include/include.htm" -->

printenv

This command prints all existing environment variables and their values. There are no attributes. For example:

<!--#printenv -->

set

This command sets the value of an environment variable. The attributes are:

var
Specifies an environment variable name.

See Environment variables on HTTP Server for a list of environment variables.

value
Specifies the value to assign to the environment variable name. For example:
<!--#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" -->

Conditional commands

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.

Variable substitution

Values can be supplied in the following ways:

  • Test can be supplied within a quoted string. For example:
    <!--#config timefmt="%b%d%y" -->
  • A literal dollar sign can be supplied in a string using a backslash. For example:
    <!--#ifexpr="$a=\$test" -->
  • A variable reference can be supplied within a character sequence using braces. For example:
    <!--#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.

Additional notes

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 &ecirc; is a client side variable, so the & is escaped to create the value ":fr&ecirc;d" or "fred" with a circumflex over the e.

<!--#set var="index" value="1"  --> 
<!--#set var+"var&index;" value+"fr\&ecirc;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