📄 ch10.htm
字号:
the NT stores all of its configuration files. It is recommended
that when you use the Registry Editor you convert it to a read-only
format by selecting the Read Only command under the Options menu.
This allows you to view all the data in the various configuration
files without the fear of accidentally overwriting crucial data.
<P>
You can usually find what you are looking for in the HKEY_LOCAL_
MACHINE subtree directory in the Registry. This is where your
hardware, software, security, system, and related configuration
files are kept. Another is the HKEY_CLASSES_ROOT where the different
file formats and data types are defined.
<H4>The Document Root</H4>
<P>
The directory tree you will likely find yourself in most of the
time, once you've gotten most of your bugs out of the way, is
the document root. This is where you keep all the HTML documents
for a Web site available for client access. All the directories
contained within the root directory are considered part of the
document root.
<P>
The root directory for your Web site might be
<BLOCKQUOTE>
<PRE>
c:/HTTP/bin/my_site
</PRE>
</BLOCKQUOTE>
<P>
and the document root for the HTML file index.htm in my_site would
then be
<BLOCKQUOTE>
<PRE>
/HTTP/bin/my_site/
</PRE>
</BLOCKQUOTE>
<H2><A NAME="PrinciplesofCGIProgramming"><FONT SIZE=5 COLOR=#FF0000>
Principles of CGI Programming</FONT></A></H2>
<P>
The Common Gateway Interface is one way for a Web server, using
HTTP, to "talk" to the operating system or the server's
machine. It works using requests from the client that are either
in standard input, <STDIN>, or environmental variables.
Because of this the CGI can go further than the slower HTML link,
which answers one client request at a time, leading to only one
specific response at a time.
<P>
Instead, the CGI can permit the Web server to provide different
documents based on the client's requests. More than this, the
CGI permits totally new documents to be written "on-the-fly"
so that customized client responses can be made. Typically, the
user inputs his or her information via an HTML form. Before discussing
that subject, however, a quick examination of HTTP headers is
in order. A closer look at the headers will give us some clues
as to how the CGI deals with data. MIME specifications for these
headers are outlined in Appendix B.
<H2><A NAME="HTTPHeaders"><FONT SIZE=5 COLOR=#FF0000>
HTTP Headers</FONT></A></H2>
<P>
The MIME specifications mentioned earlier, and explained in depth
in <A HREF="ch11.htm" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/ch11.htm" >Chapter 11</A>, are used to create HTTP headers that let the client
and server know what kind of data is being transferred between
them. From the client, HTTP sends a request header based on the
instructions found in the HTML file. The two basic methods to
retrieve data from a server are "GET" and "POST."
<P>
The default method in HTTP is GET when a request method is not
specified in the HTML document.
<P>
When GET is used, the information is sent to the server via the
URL field. If POST is used, then the data is sent as a separate
message once all the other HTTP request headers have been sent.
<P>
When the client has determined the method it will use to send
the data, it builds an HTTP header to send to the CGI program
on the server. This message is sent to the server, and there the
CGI program in question is called up by the server. You are not
restricted to sending only one header; you can also include other
headers that contain additional information for the server or
the CGI program.
<P>
The CGI program called up by the request then performs the task
requested of it, taking commands from any form data present, and
sends a message to the server concerning what kind of message
should go back to the client. Between the two of them, the server
and the CGI program, various HTTP response headers are created
and sent to the client.
<P>
One of the ways the CGI program accomplishes this is by referring
to itself as a non-parsed CGI program, or NP-CGI. This allows
the response headers it creates to be sent straight through the
server, simplifying and speeding things up by eliminating unneeded
processing, or parsing, time. The other way a CGI program sends
data is by creating only the minimum response headers necessary
(usually Content Type headers) and sending them to the server
where they are parsed.<BR>
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR VALIGN=TOP><TD WIDTH=576><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=576>
<BLOCKQUOTE>
<I>Parsing is the term used to describe the process that your computer goes through when preparing a program file for execution. When a computer parses a file, it goes though the file line-by-line, examining the syntax and looking for useful instructions
that will cause it to do some task when the program is run. </I>
</BLOCKQUOTE>
</TD></TR>
</TABLE></CENTER>
<P>
<P>
Parsing a file can cause problems in HTML files, which are not
meant to be parsed. When your computer reads these files, it could
find all manner of instructions not meant for execution that could
cause your computer to act up, or even crash.
<P>
Once all this is finished, the server will then decide if any
additional headers need to be added to the response, and then
sends it all to the client. This Content Type header is a common
header that contains the file type of data being sent in between
client and server.
<H2><A NAME="HTMLForms"><FONT SIZE=5 COLOR=#FF0000>
HTML Forms</FONT></A></H2>
<P>
You should have a strong understanding of HTML form specifications,
but the HTML form is the main way in which users will be passing
information to your server, so we will go over the details involved.
For a really in-depth tutorial on HMTL forms try
<BLOCKQUOTE>
<PRE>
<A HREF="javascript:if(confirm('http://www.netscape.com/tutorials/forms.html \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.netscape.com/tutorials/forms.html'" tppabs="http://www.netscape.com/tutorials/forms.html">http://www.netscape.com/tutorials/forms.html
</A></PRE>
</BLOCKQUOTE>
<P>
HTML forms start with the <FORM> tag. To handle specific
data the <INPUT> tag defines how the data is gathered from
the user on the page. The <SELECT> tag presents a choice
to the user for data, like a multiple choice question on a test.
<P>
The <OPTION> tag is used to present each of the choices
the user has. It is used with the <SELECT> tag. And, if
the user is inputting text, the <TEXTAREA> tag creates a
pane that will hold the user's data. This pane is scrollable.
Each of these HTML elements is modified by it own attributes.
<P>
The HTML form itself sets up paired variables of name fields with
value fields. The name variable is determined by the form, which
is matched to the value variable supplied by the user. Once the
user has supplied the information, the form has to understand
what to do with the data. This is accomplished with the method
and action attributes in the <FORM> tag.
<P>
There are several attributes in the <FORM> tag that deal
with how the form will handle the data. These include
<UL>
<LI><I>Action</I>-Where the URL of the program that needs the
input of the form is given. The default URL for this is the base
server URL where the form is located.
<LI><I>Method</I>-This denotes the method type in which the supplied
data will be sent to the URL indicated in the Action using the
proper forms-handling protocol. The two choices of method type
are GET and POST.
<LI>GET is typically used when the information being supplied
makes no "lasting" changes in the server's HTML documents
or databases. POST is used when changes <I>are </I>made to the
server's HTML documents, databases, or some other value.
<LI>Enctype-This is important. Enctype is used to give the data
its media type so that the name/value pairs will be properly encoded.
If the protocol recognized in the <METHOD> tag does not
have its own format defined, then it must be assigned using Enctype.
The format for this is
</UL>
<BLOCKQUOTE>
<PRE>
application/x-www-form-urlencoded.
</PRE>
</BLOCKQUOTE>
<P>
Name/value pairs are the way in which data values are passed to
the CGI from a form. The "name" comes from the name
assigned by the programmer in the tag requesting input. This is
paired with the input from the "value" in the same tag,
which is given by the user.
<P>
The name/value pairs will be included in the data set in the order
in which they appear in the form. The name fields are separated
from the value fields with an = symbol and the white space in
both the name and value variables is replaced with a + symbol.
They are sent to the server as name=value, with each pair of name/value
pairs separated by an & symbol. The format looks like this
<BLOCKQUOTE>
<PRE>
name1=value1&name2=value2&name3=value3
</PRE>
</BLOCKQUOTE>
<P>
or, with a real example
<BLOCKQUOTE>
<PRE>
first=Bobby&last=Hull&street=1Ø63+Golden+Jet+Lane&city=Pointe+Anne&state=
Ontario&zip=CHI+BLA&phone=61Ø.555.117Ø&address=Send+In+Your+Address+
</PRE>
</BLOCKQUOTE>
<P>
You may have noticed how long this can make the string being sent
to the server. It is important to be aware of how your server
handles long strings, so that information is not chopped off.
The POST method has no limit, as it is just a continuous string
of DATA from <STDIN>, like typing on a keyboard. If you
type fast enough, your input gets stuck in a buffer. The GET method
uses environmental variables, and it is limited to 255 characters.
<P>
These name/value pairs can be separated out using Perl. So, with
name/value pairs, the name is how your server recognizes arriving
data, while the value of that data is the value of the pair. The
name/value system applies to all the types of data submission
a user can make, from text entry to checkboxes to radio buttons.
<P>
All nonalphanumeric characters are replaced by a % symbol followed
by the two hexadecimal digits that represent their ASCII code
equivalent. Line breaks are signified as control/line feed %0D%0A.
The nonalphanumeric characters most often used from your keyboard
are symbolized by their decimal and hexadecimal equivalents, which
are found in Table 10.1.<BR>
<P>
<CENTER><B>Table 10.1 Standard ASCII Characters and Their Decimal
and Hexadecimal Equivalents</B></CENTER>
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=40% CELLPADDING=3>
<TR VALIGN=TOP><TD><CENTER><B>Character</B></CENTER></TD><TD><CENTER><B>Decimal</B></CENTER>
</TD><TD><CENTER><B>Hex</B></CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>Tab</CENTER></TD><TD><CENTER>09</CENTER>
</TD><TD><CENTER>09</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>Space</CENTER></TD><TD><CENTER>16</CENTER>
</TD><TD><CENTER>20</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>"</CENTER></TD><TD><CENTER>18</CENTER>
</TD><TD><CENTER>22</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>(</CENTER></TD><TD><CENTER>40</CENTER>
</TD><TD><CENTER>28</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>)</CENTER></TD><TD><CENTER>41</CENTER>
</TD><TD><CENTER>29</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>'</CENTER></TD><TD><CENTER>44</CENTER>
</TD><TD><CENTER>2C</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>.</CENTER></TD><TD><CENTER>46</CENTER>
</TD><TD><CENTER>2E</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>;</CENTER></TD><TD><CENTER>59</CENTER>
</TD><TD><CENTER>3B</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>:</CENTER></TD><TD><CENTER>58</CENTER>
</TD><TD><CENTER>3A</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER><</CENTER></TD><TD><CENTER>60</CENTER>
</TD><TD><CENTER>3C</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>></CENTER></TD><TD><CENTER>62</CENTER>
</TD><TD><CENTER>3E</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>@</CENTER></TD><TD><CENTER>64</CENTER>
</TD><TD><CENTER>40</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>[</CENTER></TD><TD><CENTER>101</CENTER>
</TD><TD><CENTER>5B</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>]</CENTER></TD><TD><CENTER>103</CENTER>
</TD><TD><CENTER>5D</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>\</CENTER></TD><TD><CENTER>102</CENTER>
</TD><TD><CENTER>5C</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>^</CENTER></TD><TD><CENTER>104</CENTER>
</TD><TD><CENTER>5E</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>{</CENTER></TD><TD><CENTER>113</CENTER>
</TD><TD><CENTER>7B</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>}</CENTER></TD><TD><CENTER>115</CENTER>
</TD><TD><CENTER>7D</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>|</CENTER></TD><TD><CENTER>114</CENTER>
</TD><TD><CENTER>7C</CENTER></TD></TR>
<TR VALIGN=TOP><TD><CENTER>~</CENTER></TD><TD><CENTER>116</CENTER>
</TD><TD><CENTER>7E</CENTER></TD></TR>
</TABLE></CENTER>
<P>
<P>
There are other non-alphanumeric characters that can be encoded,
as shown in Table 10.2.<BR>
<P>
<CENTER><B>Table 10.2 Non-Alphanumeric Character Encoding</B></CENTER>
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=40%>
<TR VALIGN=TOP><TD WIDTH=132><CENTER><B>Character</B></CENTER></TD><TD WIDTH=114><CENTER><B>Encoding</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=132><CENTER>? </CENTER></TD><TD WIDTH=114><CENTER>%3F</CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=132><CENTER>& </CENTER></TD><TD WIDTH=114><CENTER>%26</CENTER>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -