Your Daily Source for Apache News and Information  
Breaking News Preferences Contribute Triggers Link Us Search About
Apache Today [Your Apache News Source] To internet.com

Apache HTTPD Links
The Jakarta Project
Apache XML Project
Apache Project
Apache-Perl Integration Project
The Apache Software Foundation
Apache Module Registry
The Java Apache Project
The Apache FAQ
PHP Server Side Scripting
ApacheCon
Apache-Related Projects
The Linux Channel at internet.com
Apache Today
BSD Central
BSD Today
Linux Apps
Enterprise Linux Today
Linux Programming
Linux Central
Linux Today
All Linux Devices
Linuxnewbie.org
PHPBuilder
Linux Start
Just Linux
Linux Planet
SITE DESCRIPTIONS
Apache Guide: Advanced SSI Techniques
Jun 26, 2000, 04 :00 UTC (13 Talkback[s]) (23758 reads) (Other stories by Rich Bowen)

This is the third in a three-article series about Server Side Includes, or SSI. In the first article, I discussed configuring your Apache server to permit SSI. In the second article, I gave some examples of how you might use SSI to add dynamic content to your web pages. In this article, I'll talk about some of the advanced features available with Server Side Includes.

(Note: Most of the features discussed in this article are only available to you if you are running Apache 1.2 or later. Of course, if you are not running Apache 1.2 or later, you need to upgrade immediately, if not sooner. Go on. Do it now. We'll wait.)

Setting Variables

Using the set attribute, you can set variables for later use. We'll need this later in the discussion, so we'll talk about this here. The syntax of this is as follows:

        <!--#set var="name" value="Rich" -->

In addition to merely setting values literally like that, you can use any other variable, including, for example, environment variables, or some of the variables we discussed in the last article (like LAST_MODIFIED, for example) to give values to your variables. You will specify that something is a variable, rather than a literal string, by using the dollar sign ($) before the name of the variable:

       <!--#set var="modified" value="$LAST_MODIFIED" -->

To put a literal dollar sign into the value of your variable, you need to escape the dollar sign with a backslash:

       <!--#set var="cost" value="\$100" -->

Finally, if you want to put a variable in the midst of a longer string, and there's a chance that the name of the variable will run up against some other characters, and thus be confused with those characters, you can place the name of the variable in braces, to remove this confusion. (It's hard to come up with a really good example of this, but hopefully you'll get the point.) To wit:

       <!--#set var="date" value="${DATE_LOCAL}_${DATE_GMT}" --> 

Conditional Expressions

Now that we have variables and are able to set and compare their values, we can use them to express conditionals. This lets SSI be a tiny programming languages of sorts. mod_include provides an if, elif, else, endif structure for building conditional statements. This allows you to effectively generate multiple logical pages out of one actual page.

The structure of this conditional construct is:

    <!--#if expr="test_condition" -->
    <!--#elif expr="test_condition" -->
    <!--#else -->
    <!--#endif -->

A test_condition can be any sort of logical comparison--either comparing values to one another, or testing the "truth" of a particular value. (A given string is true if it is nonempty.) For a full list of the comparison operators available to you, see the mod_include documentation. Here are some examples of how one might use this construct.

In your configuration file, you could put the following line:

        BrowserMatchNoCase macintosh Mac
        BrowserMatchNoCase MSIE InternetExplorer

This will set environment variables Mac and InternetExplorer to true, if the client is running Internet Explorer on a Macintosh.

Then, in your SSI-enabled document, you might do the following:

        <!--#if expr="${Mac} && ${InternetExplorer} -->
        Apologetic text goes here
        <!--#else -->
        Cool JavaScript code goes here
        <!--#endif -->

Not that I have anything against IE on Macs--I just struggled for a few hours last week trying to get some JavaScript working on IE on a Mac, when it was working everywhere else. The above was the interim workaround.

Any other variable (either ones that you define, or normal enviroment variables) can be used in conditional statements. With Apache's ability to set environment variables with the SetEnvIf directives, and other related directives, this functionality can let you do some pretty involved dynamic stuff without ever resorting to CGI.

Conclusion

SSI is certainly not a replacement for CGI, or other technologies used for generating dynamic web pages. But it is certainly a great way to add small amounts of dynamic content to pages, without doing a lot of extra work.

See the docs on mod_include for more information on using SSI.

  Current Newswire:
WDVL: Perl for Web Site Management: Part 3

Retro web application framework V1.1.0 release

Leveraging open standards such as Java, JSP, XML,J2EE, Expresso and Struts.

Netcraft Web Server Survey for November is available

FoxServ 2.0 Released

Ace's Hardware: Building a Better Webserver in the 21st Century

Web Techniques: Customer Number One

Apache-Frontpage RPM project updated

CNet: Open-source approach fades in tough times

NewsForge: VA spin-off releases first product, aims for profit

 Talkback(s) Name  Date
  Another nice use of XSSI
XSSI (the inclusion of control structure) can also make page redirection available to 'the non programmer', and also save you the time of having to learn a language of cgi for the (same|similar) results...

Say you have a need to point multiple hostnames to the same server and you need a script to redirect the web entrant based on the hostname entered...

Example:

<html>
<head>
<!--#if expr="${HTTP_HOST} = /host1.urdomain.org/"-->
<META http-equiv="refresh" content="4;url=http://redirect.com/pagehere">
<body>
Redirection in Progress...
<!--#elif expr="${HTTP_HOST} = /host2.urdomain.org/"-->
<META http-equiv="refresh" content="4;url=http://redirect2.com/pagehere">
<body>
Redirection in Progress...
<!--#else -->
<body>
Welcome to my page...
<!--#endif -->
</bodygt;
</htmlgt;
  
  Jun 26, 2000, 06:04:30
  XSSI can also aid in redirection...
Very nice article Rich...
I just wanted to add:

XSSI's inclusion of control structure offers a whole new set of opportunities,
one of which is user redirection based on hostname evaluation. For instance, say you need a way to have multiple hostnames point to the same server, but you need user's connecting via these hostnames to be redirected to different urls.

Example:





Redirection In Progress...



Redirection In Progress...


Welcome To My Page...




[Sig]
Tre Harmon
http://www.lansystems.com
[EOSig]   
  Jun 26, 2000, 08:09:49
  SSI (Servlets)
Good Artice!!!

I am new(3 months) to Apache/SSI/Java. What I would like to do is use different
servlets to construct a html page shown at the browser. eg.HeaderServlet, BodyServlet, FooterServlet.

I have been pointed in the direction of JSSI. I have been unable to get my servlets to work in this way so far. Is there anybody that can help me?


bye

Kola   
  Jun 26, 2000, 09:10:31
  Using XSSI to fake randomization
I use a technic on our company's homepage to rotate some of the content, using simple conditionals and GMT time to fake random content. The GMT is a pretty set string with only a single digit changing in it.


<!--#if expr="${DATE_GMT} = /0 GMT|1 GMT/" -->
set one or #include
<!--#elif expr="${DATE_GMT} = /2 GMT|3 GMT|4 GMT/" -->
set two or #include
<!--#elif expr="${DATE_GMT} = /5 GMT|6 GMT|7 GMT/" -->
set three or #include
<!--#else -->
set four or #include
<!--#endif -->   
  Jun 27, 2000, 19:51:57
  XSSI Library
Some of you may wish to visit the XSSI Library, it has some very usable XSSI code there.   
  Jul 5, 2000, 11:58:08
  Your Site
I have been looking everywhere for a site like this. I found every thing I'd been looking the first five (5) minutes I surfed in.

Thanks,

Mike   
  Nov 20, 2000, 06:07:42
  SSI won't parse at all
Help,

I can't get Apache to parse any SSI commands on one server.
The basic directive is placed in the srm.conf file for this virtual host;


Options +Includes
AddHandler server-parsed .html


I can't even get an error from my html docs with any SSI call embedded. The server just isn't processing the directive.

Thanks,

fike@cs.utk.edu

Additional info;

[solaris] httpd -V
Server version: Apache/1.3.1 (Unix)
Server built: Sep 24 1998 16:56:43
Server's Module Magic Number: 19980713
Server compiled with....
-D HTTPD_ROOT="/usr/local/apache"
-D HAVE_MMAP
-D USE_MMAP_SCOREBOARD
-D USE_MMAP_FILES
-D USE_FCNTL_SERIALIZED_ACCEPT

============================================

[solaris] httpd -l
Compiled-in modules:
http_core.c
mod_env.c
mod_log_config.c
mod_mime.c
mod_negotiation.c
mod_include.c <-- its here
mod_autoindex.c
mod_dir.c
mod_cgi.c
mod_asis.c
mod_imap.c
mod_actions.c
mod_userdir.c
mod_alias.c
mod_access.c
mod_auth.c
mod_setenvif.c
mod_perl.c

=============================================   
  Jan 19, 2001, 20:28:32
  Try this
Try to add these lines to your access.conf file:


Options +Includes

  
  Mar 18, 2001, 15:31:28
  SSI always adds a space
Greetings,
We use SSI on Apache and particularlythe fsize feature. Every time, there is an extra space between the last character and the result of the fsize. Can this be fixed?

Thanks
George
  
  Apr 11, 2001, 19:52:35
   Re: SSI always adds a space

That "space" is probably a "newline" character after the directive.


Try something like:




more text

... and the newline after the > will be passed to the UA.


Instead, try writing:



more text
  
  May 16, 2001, 19:21:17
   Re: SSI won't parse at all

Two issues:


Parsing every .html file will be very intensive and probably (?) unnecessary. Try assigning .shtml or similar.
You don't say whether the directive appears in the UA's HTML or not...?

  
  May 16, 2001, 19:24:44
   Re: XSSI Library
The XSSI Library has moved to: http://www.ordersomewherechaos.com/~rosso/xssi/.   
  Sep 3, 2001, 19:44:57
   Re: XSSI Library
To update the above link, the XSSI Library, has moved to:

http://www.ordersomewherechaos.com/~rosso/xssi/   
  Oct 8, 2001, 02:48:25
Enter your comments below.
Your Name: Your Email Address:


Subject: CC: [will also send this talkback to an E-Mail address]
Comments:

See our talkback-policy for or guidelines on talkback content.

About Triggers Media Kit Security Triggers Login


All times are recorded in UTC.
Linux is a trademark of Linus Torvalds.
Powered by Linux 2.4, Apache 1.3, and PHP 4
Copyright INT Media Group, Incorporated All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/