Conditional Statements
Apache allows you to include only select portions of a server document
using conditional statements. These conditional statements are based on
the value of server-side variables initialized earlier
using the SSI set
command. The Apache flow-control
statements allow you to effectively customize a document without adding
more complex CGI programs to perform the same task.
There are four Apache flow-control statements:
<!—#if expr="expression" --> <!—#elif expr="expression"--> <!--#else--> <!--#endif—>
Each works as you would expect from an ordinary scripting language.
Note that each if
must have a closing endif
server-side statement. For example:
<!--#if expr="$myvar=activated" --> <B>The variable appears to be activated</B> <!--#elif expr="$myvar=inactive"--> <B>The variable appears to be inactive</B> <!--#else--> <B>The variable has an unknown value</B> <!--#endif—>
Table 13.2 shows the allowed expressions, where the order of operations
is as expected in a traditional programming language. Note that in some
cases, var2 is allowed to be an egrep
-based regular
expression if it is surrounded by slashes (/
) on both sides.
Table 13-2. XSSI Conditional Expressions
Expression | Meaning | |
---|---|---|
var | True if the variable is not empty | |
var1=var2 | True if the variables match | |
var1!=var2 | True if the variables do not match | |
var1<var2 | True if the first variable is less than the second | |
var1<=var2 | True if the first variable is less than or equal to the second | |
var1>var2 | True if the ... |
Get Webmaster in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.