📄 ch11.htm
字号:
<LI>There are no spaces in the beginning of an SSI line of code.
It should always be <!--#command.
<LI>There should always be one space after the argument_value,
as "jazzquotes.html" -->.
<LI>The argument_value should always be surrounded by double quotation
marks.
<LI>SSI recognizes only path names that start either at the server
root or are in a subdirectory of the directory where the SSI file
is found. Do not use any backslashes in the path name.
</UL>
<H3><A NAME="SSICommands">
SSI Commands</A></H3>
<P>
The command, config, short for configuration, does not appear
in HTML documents. This command is used to change the expression
of your other SSI commands as they appear in your HTML documents.
<P>
With the config command you can control the standard text output
of any SSI command. For example, if you wanted to change how the
date is sent back to the user from this format-Monday, May 11
10:32:43 EST 1996-to one more user-friendly, you would do this
by modifying the flastmod command. You can also modify the error
message that is sent out and the way the file size is formatted.
<P>
If you want to change the date, you use the command_argument timefmt
in the SSI command. For the argument_value you can use any of
these:
<UL>
<LI>%a-Abbreviates weekday name, based on present locale.
<LI>%A-Gives full weekday name, based on present locale.
<LI>%b-Abbreviates month name, based on present locale.
<LI>%B-Gives full month name, based on present locale.
<LI>%c-This is the preferred date and time display for the present
locale.
<LI>%d-Decimal number from 0 to 31 that represents the day of
the month.
<LI>%H-Decimal number from 00 to 23 that represents the hour of
24-hour measured time.
<LI>%I-Decimal number from 01 to 12 that represents the hour of
12-hour measured time.
<LI>%j-Decimal number from 001 to 366 that represents the day
of the year.
<LI>%m-Decimal number from 1 to 12 that represents the month.
<LI>%M-Decimal number from 00 to 59 that represents the minute.
<LI>%p-Gives a.m. or p.m. based on the time value, or the corresponding
strings for the present locale.
<LI>%S-Decimal number from 00 to 59 that represents the second.
<LI>%U-Decimal number from 1 to 52 that represents the number
of the week of the current year. It begins with the first Sunday
of the first week.
<LI>%w-Decimal number from 1 to 6 that represents the days of
the week, beginning with Sunday.
<LI>%W-Decimal number from 1 to 52 that represents the number
of the week of the current year. It starts with the first Monday
of the first week.
<LI>%x-This is the preferred date and time display for the present
locale, minus the time.
<LI>%X-Gives the preferred time configuration based on the present
locale, minus the date.
<LI>%y-Decimal number from 00 to 99 that represents the year,
excluding the century.
<LI>%Y-Decimal number from 00 to 99 that represents the year,
including the century.
<LI>%Z--Gives the time zone, name, or abbreviation.<BR>
These command argument values could be used as such:
</UL>
<BLOCKQUOTE>
<PRE>
Today is <!--#config timefmt="%a" --> <!--#echo var="DATE_LOCAL" -->
</PRE>
</BLOCKQUOTE>
<P>
or
<BLOCKQUOTE>
<PRE>
You accessed this page on hour <!--#config timefmt="%H" --> <!--#echo var="TIME_HOUR" -->
</PRE>
</BLOCKQUOTE>
<P>
It is important to include the appropriate echo command for the
server to return the desired response to the client.
<P>
The include command is the most basic of the SSI commands. It
is most commonly used to add files to HTML that are needed in
a variety of places. This eliminates the need to cut and paste
that data each time by the use of the one line SSI command instead.
<P>
There are two command arguments: file and virtual. File indicates
any file in the current directory, or in a subdirectory of the
current directory. Virtual indicates any file that is originated
at the root directory. The argument values for each are the actual
path and file names, like this:
<BLOCKQUOTE>
<PRE>
<!--#include file="/addresses/ad_mailing.html" -->
</PRE>
</BLOCKQUOTE>
<P>
which automatically adds my mailing address to the HTML documents
that need it.
<P>
The virtual command argument causes the server to look for the
file in question in the root directory, as designated by the srm.conf
file. When using the virtual command, the path name must be preceded
by a backslash, and then the entire path name must be included.
This differs from the file command argument which cannot start
with a backslash, because it can look only in the current directory,
or subdirectory, as the .shtml file is in, and not above it.
<P>
The kinds of files you can include are not limited to text only
or HTML only files, but can be other SSI parsed files, excluding
those that include the include command argument.
<P>
The task of the flastmod command is to note when changes were
last made to a file, hence the name f(ile)lastmod(ified). As with
the include command, flastmod uses file and virtual as its command
arguments. The same rules apply to these command arguments as
to the include command. Flastmod is used to indicate to the user
the last time a file, like a Web zine, was modified, so that users
will know if the information is new to them.
<P>
The fsize command is concerned with the size of the file. This
command is handy when dealing with thumbnails of images on a home
page that lead to the larger versions. The fsize command can indicate
the size of each image, so users can decide if they have the time
to view it. This also helps with downloads.
<P>
The fsize command accepts both the file and virtual command arguments,
like the flastmod and include arguments, with the same parameters.
<P>
With the echo command on, SSI works with five command arguments.
Unlike previous command arguments, the items below are not case-sensitive:
<UL>
<LI>DATE_LOCAL-This creates the current time and date based on
the time zone indicated by the server and the server software.
The output can be modified using the command config and the command
argument timefmt.
<LI>DATE_GMT-This is the current time and date based on Greenwich
Mean Time, the common time reference accepted on the Internet.
<LI>DOCUMENT_NAME-This is the file name of the main document.
<LI>DOCUMENT_URI-This is the path name and file name of the main
document. A URI (Universal Resource Indicator) can be considered
the same as an URL.
<LI>LAST_MODIFIED-This is the time and date the main document
was last modified based on the last time the document was
saved, surprise, surprise.
</UL>
<P>
The command argument used with the echo command is var. A typical
use of the echo command might look like this:
<BLOCKQUOTE>
<PRE>
<!--#echo var="document_URI" -->
</PRE>
</BLOCKQUOTE>
<P>
where the document_URI refers to the URI of the first document
first parsed by the server. Although there are technical differences,
you can consider a URI the same as an URL. This variable refers
to the URI/URL of the first file that sets the value for echo
variables.
<P>
When you get to debugging SSI, and the echo command, the server
will return the word (none), in brackets, when it cannot find
the variable it is supposed to echo.
<P>
The exec command deals with controlling the operating system from
inside the SSI HTML. Most of the commands regularly available
from the command line are also available to the exec command.
This makes the exec command very powerful, so powerful that, just
like SSIs, it may be turned on or off by the server.
<P>
Using the exec command, an SSI file can automatically access a
shell or execute a CGI script. Client response is not necessary
for this to happen. The various shell commands available to the
exec command allow the SSI script to use any of the environmental
variables discussed earlier.
<P>
The command argument for the exec command is "cmd."
The argument variables available to exec are all the arguments
available to the current shell. The many options available to
you are best utilized when you have a greater understanding of
UNIX and the shells it uses, like the Bourne or Korn shells. The
most important shell to learn is the one you may have on your
server. The exec command can also be used with CGI and Perl.
<P>
To use the exec command with CGI, the command argument "cgi"
is used instead of "cmd." This allows you to execute
a CGI script inside SSI. One drawback is that the SSI still needs
the CGI script to create its own headers, so an NPH-CGI script
(non-parsed header) will not work. This is why you should not
use NPH-CGI scripts in any SSI files because the NPH-CGI script
will not generate the necessary header for the SSI file. Without
the header, the client will be unable to use, or view, the returned
file.
<P>
This last tip about SSIs is related to speed. In the various descriptions
of the commands you may have noticed the server starts looking
in the immediate directory, then proceeds down from there. To
speed things up you can place the SSI files in the same directory
as the .shtml file that calls it, and not in a subdirectory.
<H2><A NAME="HowCGIWorks"><FONT SIZE=5 COLOR=#FF0000>
How CGI Works</FONT></A></H2>
<P>
The basic model of how the CGI works is fairly straightforward.
When a user's browser, called the client, contacts your server,
it may ask for a special, non-HTML file to be accessed. The server
then accesses this file and returns any results to the client.
<H3><A NAME="ADemonstration">
A Demonstration</A></H3>
<P>
Remembering our HTML form document<B> </B>from <A HREF="ch10.htm" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/ch10.htm" >Chapter 10</A>, where
each element of an HTML form was demonstrated, it would be nice
if we could apply that to the CGI. In a very simple way we can.
This next HTML document does not lead to another HTML document,
but uses CGI to call the page from your CGI bin, or "cgi-bin"
as you will come to know it in your scripts and directory trees.
The HTML tags are self-explanatory, and the document uses the
METHOD=GET command to pass data to your CGI script.
<BLOCKQUOTE>
<PRE>
<HTML>
<HEAD>
<TITLE>The Submission Page</TITLE>
</HEAD>
<BODY>
<H2>Press this button and submit to me!</H2>
<FORM Method="GET" Action="/cgi-bin/submit.pl">
<INPUT type="submit" value="Total Submission">
</FORM>
<HR NOSHADE>
</BODY>
</HTML>
</PRE>
</BLOCKQUOTE>
<P>
This produces something like the screen in Figure 11.3.
<P>
<A HREF="f11-3.gif" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/f11-3.gif"><B>Figure 11.3 :</B> <I>The submission page- passing data to the
CGI</I>.</A>
<P>
In submit.html, the user selects the submit button which tells
the server to call the file in the cgi-bin named submit.pl. When
the server looks for this file, this is what it finds:
<BLOCKQUOTE>
<PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -