BigNoseBird.Com- Home Small Logo
The 508 Compliant Guide to 
       Big Nose Bird
BACK

Put Smarts into Your Pages with
E X T E N D E D
Server Side Include Directives

Note: This page is primarily geared towards users of the Apache family of web servers. If you are using Netscape Server or IIS, you will need to check their documentation for the their solutions. Users of Stronghold and other Apache offspring should be okay.
What is an Extended Server Side Include?
Imagine being able to put actual, real computer logic into your HTML pages? Being able to tailor your pages to specific browsers, or even show particular images- all without using CGI or JavaScript.

This allows you to present your content in a way that is not dependant on JavaScript being enabled, or having people look at your source code to see what the other guy sees!

This is a major benefit to many hosted people that have SSI, but not CGI scripting.

The basis of the this little bit of magic is the ability to use good old IF logic.

Introducing the Basic IF - ELSE - ENDIF
If you have never worked with a programming language before, this may at first appear to be somewhat strange. If you know the slightest drop of any language, you will be able to pick this up in just a few minutes. Once you get the hang of it, you will wonder how you ever lived without it.

The most simple example involves testing to see if some condition is TRUE or FALSE and then acting on it. Consider the following statement:

You are not using an MSIE Browser
Okay, a cheap parlour trick... The point is this. CGI was not required, and it is much more useful than simply echoing the HTTP_USER_AGENT variable like that annoying:
Hi! You are using CCBot/2.0 (http://commoncrawl.org/faq/)
Accomplishing this was not difficult and the entire trick are the few lines below. Please don't bother viewing the actual source code, all that is returned to you is what I have directed the server to tell you. ;-)

<!--#if expr="${HTTP_USER_AGENT} = /MSIE/" -->
  <B>You are using some kind of MSIE Browser</B><BR>
 <!--#else -->
  <B>You are not using an MSIE Browser</B><BR>
<!--#endif -->

NOTE: The placement of spaces (or lack of them) is critical to making this work. Please look at the code carefully!
Sparing you the gore for the moment, here is what is happening. The server reads the page and has a little discussion with itself.
Hmmm... If the client is using a browser that contains MSIE in its description, let me say so, else let me say something else.
In terms of how things are structured, if the if is TRUE then all of the lines up until the else are included on the page. If the if is FALSE, then all the lines between else and endif are presented to the browser. Got that?

It is not necessary to use an else, but normally you will to handle exceptions- cases that do not fall into one of your tests.

Using IF - ELSE Logic To Do Even More.
Now put on your thinking cap and consider that you not only can stick HTML in your logic, but also any other type of SSI directive that you could want. Getting some ideas yet? Look at this example.

<!--#if expr="${HTTP_USER_AGENT} = /MSIE/" -->
  <!--#include file="file1.txt" -->
 <!--#else -->
  <!--#include file="file2.txt" -->
<!--#endif -->

Results in the following:

This is text that is contained in file2.txt
I guess you are not using MSIE!

In this example, our server asked itself the same question as in the last example, but rather than just return some HTML, it copied in the contents of the desired file. Hey, if you are doubting any of this, come back and try it with a different browser. We love traffic!

What IS This EXPR Thing?
The expr is a unix'ism. What you need to know for now is this: If what is between the quote marks is TRUE, then what follows the if is done, else it is not.

You can also test for something NOT being TRUE and then acting on it. Just replace add an exclamation (!) mark before the equal (=) sign in your test.

<!--#if expr="${HTTP_USER_AGENT} != /MSIE/" -->
This test will prove TRUE ONLY IF MSIE IS NOT in the HTTP_USER_AGENT value. Quite often it is easier to work out a logical problem from the NOT than the IS.

What About The /Stuff/ Between The Slashes
In our expr tests so far, we have been doing what is called pattern matching. The rules used are the same as those employed by the unix egrep utility, and are also referred to as regular expressions. To say the least, learning regular expressions is important, but for our purposes, we will stick to simple matches.

 


Find or Give Help on the BBS
 
Home Top E-Mail
If it looks great, it's by Christine
Some Fine Print
© 1997-2003 BigNoseBird.Com®, Inc. All rights reserved. All other trademarks are the sole property of their respective owners. The products that we recommend are only ones that we use. We have no relationship with any of the authors or their companies. We cannot assume responsibility for their ultimate performance or lack of same. We also cannot assume responsibility for either any programs provided here, or for any advice that is given since we have no control over what happens after our code or words leave this site. Always use prudent judgment in implementing any program- and always make a backup first! For further information, please read our Privacy Statement. We can be contacted at webmaster@bignosebird.com.


<reallybig.com>
Web Builder Network Portal
Advertise
on the
Reallybig.com
Network
BigNoseBird Newsletter
Subscribe
Un-Subscribe


Sign up today to receive our low volume newsletter. Tips, tricks, news, and whatever else crosses our minds.
Back Issues
Privacy Statement