home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


A typical use for the include command is a closing tag line at the bottom of a page. Let’s say you’re working in the directory /home/susan, and you create a simple text file called email.htm:

Click <A HREF=“mailto:susan@nowhere.com”>here</A> to send me email.

Next, you create index.shtml, which is the default page for /home/susan, as follows:

<HTML>
<HEAD><TITLE>Susan’s Home Page</TITLE></HEAD>
<BODY>
<H1>Susan’s Home Page</H1>
Hi, I’m Susan.  <!--#include file=“email.htm”-->
See you later!
</BODY>
</HTML>

When index.shtml appears, the contents of email.htm are inserted, resulting in the following being sent to the browser:

<HTML>
<HEAD><TITLE>Susan’s Home Page</TITLE></HEAD>
<BODY>
<H1>Susan’s Home Page</H1>
Hi, I’m Susan.  Click <A HREF=“mailto:susan@nowhere.com”>here</A>
to send me email.  See you later!
</BODY>
</HTML>

You can use the email.htm file in as many other files as you want, limiting the places where you need to change Susan’s email address to exactly one.

exec

You can turn off the exec command on some servers while leaving other SSI functions enabled. If you are the system administrator of your server, study your setup and security arrangements carefully before enabling exec.

exec is a very powerful and almost infinitely flexible command. An SSI exec is very much like regular CGI in that it spawns a subprocess and lets it open files, provide output, and do just about anything else an executable can do.


NOTE:  On Netscape and NCSA servers, your SSI executable must be named *.cgi and probably will have to live in a centrally managed cgi-bin directory. (The Apache server gives you a bit more flexibility, allowing you to control the extensions of programs used for SSI.) Check your particular server’s documentation and your system setup to find out. Again, keep the documentation handy—you’ll need it again in just a moment.

The exec command typically takes one attribute, most frequently called cgi but also exe, script, and cmd on various servers. Some servers let you specify two different ways to execute programs. For example, <!--#exec cgi or <!--#exec exe usually means to launch a program and treat it just like a CGI program. <!--#exec cmd usually means to launch a shell script (called a batch file in the PC world). Shell scripts are often, but not always, treated specially by the server. In addition to launching the shell, or command processor, and passing the script name as the parameter, the server often forges the standard MIME headers, relieving the script of that duty. You have only one way of knowing how your server handles this process: If you haven’t found your server’s documentation yet, stop right now and get it. There are no rules of thumb, no standards, and no rational ways to figure out the syntax and behavior.

Here’s a trivial example of using a shell script on a UNIX platform to add a line of text. Start with a file called myfile.shtml, which contains the following somewhere in the body:

Now is the time
<!--#exec cgi=“/cgi-bin/foo.cgi” -->
to come to the aid of their country.

Then create the shell script foo.cgi and place it in the /cgi-bin directory:

#!/bin/sh
echo “for all good persons”

When you then access myfile.shtml, you see the following:

Now is the time for all good persons to come to the aid of their country.

Note that this example assumes you have configured your server to require that SSI scripts live in the /cgi-bin subdirectory, and that you have designated .cgi as the correct extension for scripts.


NOTE:  Some implementations of SSI allow you to include command-line arguments. Sadly, NCSA isn’t one of them (although Apache is). Each server has its own way of handling command-line arguments, of course. Consult your trusty documentation yet again to find out if, and how, your server allows this feature.

The SPRY Mosaic server from Compuserve actually uses an args key for arguments. A typical SPRY Mosaic script might be invoked the following way:

<!--#exec script=“scriptname.exe” args=“arg1 arg2 arg3” -->

Process Software’s Purveyor allows arguments, even though no documentation is available to support the mechanism. With Purveyor, you supply the arguments exactly as you would on a real command line:

<!--#exec exe=“\serverroot\cgi-bin\scriptname arg1 arg2 arg3” -->

Other Commands

Your server probably supports as many as a dozen commands in addition to the three covered in the preceding sections. Following are some of the most common, with a brief explanation of each:

  config errmsg=“message text” Controls which message is sent back to the client if the server encounters an error while trying to parse the document.
  config timefmt=“format string” Sets the format for displaying time and date information from that point in the document on.
  sizefmt Format varies widely among servers. This command controls how file sizes appear—as bytes, formatted bytes (1,234,567), kilobytes (1234K), or megabytes (1M).
  fsize file=“filespec” Reports the size of the specified file.
  flastmod file=“filespec” Reports the last modification date of the specified file.
  counter type=“type” Displays the count of hits to the server as of that moment.

Sample SSI Programs

This section presents the complete C code for several useful SSI programs. Some of them are platform-independent; others make use of some special features in the Windows NT operating system. You can find the source code, plus compiled executables for the 32-bit Windows NT/Windows 95 environment, on the CD-ROM accompanying this book.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.