⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch11.htm

📁 美国Macmillan出版社编写的Perl教程《Perl CGI Web Pages for WINNT》
💻 HTM
📖 第 1 页 / 共 4 页
字号:
intelligence for their toasters.

<P>

But, as with most of C's features, there is a &quot;very good&quot;

and &quot;very bad&quot; side to each. The tie to UNIX makes it

a natural for UNIX boxes, and UNIX programmers. Those of us who

are working in different environments, such as Windows NT, have

special concerns that do not mesh easily with the UNIX world,

some of which have already been mentioned in this book. With UNIX,

the operating system works without the additional level of the

graphical interface that Windows NT has, making UNIX closer to

the actual operating system. This is ideal for C, which also works

closely with the operating system. With Windows NT, the graphical

interface level creates a layer of difficulty for C that has to

be overcome.

<P>

There is also no file I/O or OS interfacing in a low-level language

such as C. Many of the other features expected from a higher-level

language (such as Perl) are available only in procedural script

libraries with C. Each OS will have its own specifics when it

comes to these libraries.

<P>

There is a great debate raging, as there always is, as to whether

or not C or Perl is the superior CGI language. I have a sneaking

suspicion that those people who learned to program with C will

favor C, and those who learned with other languages will favor

those languages. Perl is a language that excels when it deals

with text manipulation. The CGI environment's biggest demand is

the ability to deal with text smoothly, making Perl an obvious

best choice.

<P>

C++ is a superset of C, meaning that its functions and operators

are built on C, so the concerns that are raised with C also apply

to C++ as far as the scope of this book is concerned.

<H4>REXX</H4>

<P>

REXX is a language that was developed at IBM in the late 1970s.

Mike Cowlishaw developed REXX as a procedural language.

<P>

One problem with REXX is that there is still no formal standard.

Although most REXX scripts are portable, there is no standard

specification that applies to REXX, so there can be irregularities

that need to be addressed when using REXX scripts from another

operating system. It is also not as popular as Perl or C for CGI

programming, so there is much less &quot;out there&quot; for REXX

in the way of support and script libraries. REXX, however, has

been ported to just about every platform, including OS/2, Macintosh,

Amiga, AS/400, and mainframes such as VM and MVS.

<P>

This is not to make the claim that Perl is the be all and end

all of CGI programming. The more a Web Master knows, the more

tricks he or she has to solve problems. Complex sites will often

contain some Perl and C scripts. In addition, the CGI languages

mentioned here are only a few of the those currently available.

Because CGI is only a specification, not a language itself, there

are no real restrictions on what can be used for it. For more

information on REXX, read M.F. Cowlishaw's book, <I>The REXX Language,

A Practical Approach to</I> <I>Programming</I> (Prentice-Hall,

1985). This is the closest thing there is to a formal REXX standard.

You can also try these Web sites:

<BLOCKQUOTE>

<PRE>

<A HREF="javascript:if(confirm('http://www.pvv.unit.no/RexxLA/index.htmlhttp:/www2.hursley.ibm.com/rexx/ftp:/rexx.uwaterloo.ca/pub/rexxfaq.txt  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.pvv.unit.no/RexxLA/index.htmlhttp:/www2.hursley.ibm.com/rexx/ftp:/rexx.uwaterloo.ca/pub/rexxfaq.txt'" tppabs="http://www.pvv.unit.no/RexxLA/index.htmlhttp:/www2.hursley.ibm.com/rexx/ftp:/rexx.uwaterloo.ca/pub/rexxfaq.txt">http://www.pvv.unit.no/RexxLA/index.html

http://www2.hursley.ibm.com/rexx/

ftp://rexx.uwaterloo.ca/pub/rexxfaq.txt

</A></PRE>

</BLOCKQUOTE>

<H4>Python</H4>

<P>

Python was developed in Amsterdam, The Netherlands, by Guido van

Rossum for a company called Stichting Mathematisch Centrum. It

is a new language that goes even further in being readable than

Perl.

<P>

Python, like Perl, is an interpreted language, so like Perl the

Python interpreter must be installed on your server to use it.

From the start Python was developed as an object-oriented language,

so it is a strong, effective language for programming CGI.

<P>

Python's most interesting feature is its huge library of functions.

It can use these to communicate over networks or to access system-specific

functions. There is also a CGI library that is available to programmers.

Some of the functions in the library include parsing, printing

the defined environmental variables (to aid in debugging), and

printing the contents of an HTML form. To attest to Python's usefulness

it was used to create Infoseek's search engine, and all of its

other programs. More information about Python can be found at

<BLOCKQUOTE>

<PRE>

<A HREF="javascript:if(confirm('http://www.python.org/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.python.org/'" tppabs="http://www.python.org/">http://www.python.org/</A>

comp.lang.python

</PRE>

</BLOCKQUOTE>

<H2><A NAME="ServerSideIncludes"><FONT SIZE=5 COLOR=#FF0000>

Server-Side Includes</FONT></A></H2>

<P>

There is one other area of CGI that warrants attention before

concluding this section. To provide greater usefulness to your

users, you might want to have Server Side Includes as a service

available on your Web server. It is important to note that although

the NSCA and Netscape HTTP servers do support Server Side Includes,

or SSIs, at the time this book goes to press, the CERN HTTP server,

EMWAC HTTP server, and IS do not provide such support. There are,

however, several other HTTP servers available, which also support

SSIs. CERN has announced plans to make SSIs a part of their server

in the future.

<P>

Although SSIs are not strictly in the realm of the CGI, they are

included here because they may solve some problems you may have

with some of your Web pages. Remember, you want to have as many

problem-solving strategies as possible available because many

problems require more than one strategy to be solved successfully.

<P>

SSIs denote the handling of special extensions to HTML tags. Resembling

HTML documents, SSI files are very similar to HTML files. SSI

files differ from HTML in their use of a superset of the CGI environmental

variables. This does not make SSI files particular to the CGI,

because SSI files do not have to have a gateway to operate.

<P>

SSIs do not run automatically. You have to enable them on your

server before they will work. Please check your HTTP server's

documentation for the way in which to enable SSIs.

<P>

It is important to know that although SSIs add a lot to a Web

site, they also place a greater demand on your server's resources.

For SSIs to run, the server has to read, or parse, every line

of the SSI file to find the special SSI commands. If you find

your server is becoming overworked, one quick way to deal with

the traffic overload is to disable the SSI capacity on your server.

Be very careful not to identify every HTML file as an SSI extension,

or then your server will parse every HTML file that is accessed.

In turn, this creates a huge drain on your server's resources

and a time lag in satisfying the client's request. Typical SSI

files have .shtml as their file extension. 

<P>

Comparing SSIs with HTML will give you a clearer picture. Because

SSIs are parsed by the server into HTML before they go to the

browser, an SSI file looks very similar to an HTML file. This

is file jazz.shtml.

<BLOCKQUOTE>

<PRE>

&lt;HTML&gt;

&lt;HEAD&gt;

&lt;TITLE&gt;Jazz on the Web&lt;/TITLE&gt;

&lt;/HEAD&gt;

&lt;BODY&gt;

&lt;H1&gt;Jazz on the Web!&lt;/H&gt;&lt;BR&gt;

&lt;H2&gt;

This site was last modified on &lt;!--#echo var=&quot;LAST_MODIFIED&quot; --&gt;

&lt;/H&gt;

&lt;HR&gt;

&lt;A HREF=&quot;http://town.hall.org/Archives/radio/Kennedy/Taylor/&quot;&gt;&lt;H1&gt;Jazz Styles&lt;/A&gt;&lt;/H&gt;

&lt;A HREF=&quot;http://www.yahoo.com/Entertainment/Music/Artists/By_Genre/Jazz/&quot;&gt;

&lt;H1&gt;Jazz Musicians&lt;/A&gt;&lt;/H&gt;

&lt;A HREF=&quot;http://www.yahoo.com/Entertainment/Music/Genres/Jazz/Labels/&quot;&gt;

&lt;H1&gt;Jazz Labels&lt;/A&gt;&lt;/H&gt;&lt;BR&gt;&lt;BR&gt;

&lt;H2&gt;The jazz quote of the day is:&lt;/H&gt;&lt;BR&gt;

&lt;!--#include virtual=&quot;quotes&quot; file=&quot;jazzquotes.html&quot; --&gt;

&lt;/BODY&gt;

&lt;/HTML&gt;

</PRE>

</BLOCKQUOTE>

<P>

This file looks like a regular HTML document, except for two lines.

The first line shows a very common use of SSI, which is to keep

a running update on when the page was last modified.

<P>

The server reads the line

<BLOCKQUOTE>

<PRE>

This site was last modified on &lt;!--#echo var=&quot;LAST_MODIFIED&quot; --&gt;

</PRE>

</BLOCKQUOTE>

<P>

and sees that it has to resolve the variable LAST_MODIFIED, which

it then echoes to the client in HTML. The second line not standard

to HTML is

<BLOCKQUOTE>

<PRE>

&lt;!--#include virtual=&quot;quotes&quot; file=&quot;jazzquotes.html&quot; --&gt;

</PRE>

</BLOCKQUOTE>

<P>

which the server parses and then sees it has to add the file jazzquotes.html

to the page before it sends the data to the browser. The end result

looks something like Figure 11.2.

<P>

<A HREF="f11-2.gif" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/f11-2.gif"><B>Figure 11.2 :</B> <I>An example SSI file parsed in HTML</I>.</A>

<P>

It is interesting to note that when the server returns the called

SSI file, jazz.quotes.html, it not only attaches the file to the

new, parsed HTML file, but in the exact place where the SSI line

of code is in the unparsed .shtml file.

<P>

If your haven't already noticed, SSI commands are an adaptation

of the HTML comment tags. This was intentional, so that if you

move your HTML documents, which contain SSIs, to another server,

they will look the same, regardless of whether that server supports

SSIs or not. Inside the HTML comment form the SSI syntax looks

like this:

<BLOCKQUOTE>

<PRE>

&lt;!--#command cmd_argument=&quot;argument_value&quot; --&gt;

</PRE>

</BLOCKQUOTE>

<P>

where the command is a special SSI command, the cmd_argument is

related to the SSI command, and the argument_value is based on

the cmd_argument.

<H3><A NAME="SSISyntax">

SSI Syntax</A></H3>

<P>

There are six commands for SSI. They are config, echo, exec, fsize,

flastmod, and include. Their functions are listed in Table 11.1.

<BR>

<P>

<CENTER><B>Table 11.1 SSI Syntax</B></CENTER>

<P>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR VALIGN=TOP><TD WIDTH=108><CENTER><B>Command</B></CENTER></TD><TD WIDTH=468><B>Function</B>

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=108>config</TD><TD WIDTH=468>This sets the format of the size, time, or error messages.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=108>echo</TD><TD WIDTH=468>This will place the value of the SSI variables into an HTML document.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=108>exec</TD><TD WIDTH=468>Will execute a CGI program or system command, and output the result into the HTML document.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=108>Fsize</TD><TD WIDTH=468>Places the size of the file in the HTML document.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=108>Flastmod</TD><TD WIDTH=468>Places the date of the last modification of an HTML document into that HTML document.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=108>Include</TD><TD WIDTH=468>Places the contents of other HTML documents into the HTML document, or specified data file.

</TD></TR>

</TABLE></CENTER>

<P>

<P>

When working with SSI commands, it is important to remember these&nbsp;rules:

<UL>

<LI>SSI syntax is based on UNIX commands, which are case-sensitive.

Config is not the same as config.

<LI>SSI requires the right file extension if it is to be recognized

and parsed by the server. Make sure your SSIs are .shtml. You

can also turn parsing on for all documents on your server, or

set the file's attributes, like the execute or archive bit. You

also must make sure that your server is aware of this file type

by associating the extension using File Manager.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -