Conditional Expressions

SSI has the ability to include text based upon conditions. You can use this for a large number of applications:

The format of the SSI "if" directive is as follows:

<!==#if "<op1>" operator "op2"> operation to perform -->

where:

<op1> is the first operand of the logical comparison

<op2> is the second operand

Note: <op1> and <op2> must be surrounded with && characters if they are reserved words. For example, &&HTTP_USER_AGENT&& is equated to the user agent (spider or browser name) while HTTP_USER_AGENT is simply the string "HTTP_USER_AGENT".

<operator> is the method of comparison (see table below)

operation to perform is what to do if the comparison is TRUE.

Operators for Conditional Expressions
Operator Name Result
== equalto  TRUE if op1 is equal to op2
!= notequalto  TRUE if op1 is not not equal to op2
< lessthan  TRUE if op1 is less than op2
> greaterthan  TRUE if op1 is greater than op2
!< notlessthan  TRUE if op1 is  not less than op2
!> notgreaterthan  TRUE if op1 is not greater than op2
  hasstring TRUE if text string op2 is contained in text string op1 

There are a number of actions that you can take if the expression is true.

goto <label> where <label> is a string defined by the "label" directive. This is create for skipping around conditional information.

print <text> causes the text to he printed. This may be any text or HTML tag.

error causes the config.error text to be displayed.

break stops transmitting the HTML back to the client. In other words, it ends the page.

errorbreak causes the error and break directives to be executed.

printbreak causes print and break directives to be executed.

The "label" directive is closely related and has the following format.

<!--#label <label> --> where <label> is the name of the label. Used as target for "goto".

Here are some examples of conditional SSI directives.

<!--#if "&&HTTP_USER_AGENT&&" hasstring "EmailSiphon" goto idiot -->
<p>Begin normal HTML document</p>
<!--#goto end -->
<!--#label idiot -->
<!--#include virtual "/stuff/poisonpill.htm" -->
<!--#label end -->

The above example uses SSI to modify the HTML code if the spider called EmailSiphon is identified as the user agent reading the page. In this case, a file called "poisonpill.htm" is included. Otherwise, the page is displayed normally (without the reference to poisonpill).

<!--#if "&&HTTP_USER_AGENT&&" hasstring "Cherry" break -->

This example is much simpler. Find the "bad" referrer, simple stop processing.

 

Internet Tips Contents
404 Errors Advertising Autoresponse Awardmaster Basics Browsers Careers Chatting Disasters Domains Email Emoticons Ezines Free Stuff Fun Stuff FTP Graphics Homepages HTML Reference HTML Tutorial Interactive Legal Links Msg Boards Microsoft Money Multimedia Networks Newsgroups Newsletter Products RFC's Ringmaster Searches Security Sticky Sites Surfing TANSTAAFL Telnet Viral Webmaster Your System