|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
A typical use for the include command is a closing tag line at the bottom of a page. Lets say youre 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>Susans Home Page</TITLE></HEAD> <BODY> <H1>Susans Home Page</H1> Hi, Im 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>Susans Home Page</TITLE></HEAD> <BODY> <H1>Susans Home Page</H1> Hi, Im 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 Susans 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.
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 havent found your servers 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. Heres 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.
Other CommandsYour 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:
Sample SSI ProgramsThis 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.
|
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. |