Put Smarts
into Your Pages with
|
|||||||||||||||||||||||||||
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
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 BrowserOkay, 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/1.0 (+http://www.commoncrawl.org/bot.html)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. ;-)
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.
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?
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.
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
|
|
|
|
|
| <reallybig.com>
Web Builder Network Portal |
| Advertise on the Reallybig.com Network |
| BigNoseBird Newsletter |
|
|