appb_16.htm
来自「by Randal L. Schwartz and Tom Phoenix I」· HTM 代码 · 共 141 行
HTM
141 行
<html><head><title>The Common Gateway Interface (CGI) (Learning Perl, 3rd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Randal L. Schwartz and Tom Phoenix" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596001320L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Learning Perl, 3rd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Learning Perl, 3rd Edition" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="appb_15.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"></a></td><td align="right" valign="top" width="228"><a href="appb_17.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">B.16. The Common Gateway Interface (CGI)</h2><p>One of the most popular uses for Perl on the<a name="INDEX-1274" />Web is in writing CGI programs. These runon a web server to process the results of a form, perform a search,produce dynamic web content, or count the number of accesses to a webpage.</p><p>The <tt class="literal">CGI</tt><a name="INDEX-1275" /> module, which comes with Perl, providesan easy way to access the form parameters and to generate some HTMLin responses. (If you don't want the overhead of the full<tt class="literal">CGI</tt> module, the<tt class="literal">CGI_Lite</tt><a name="INDEX-1276" /> module provides access to the formparameters without all the rest.) It may be tempting to skip themodule and simply copy-and-paste one of the snippets of code thatpurport to give access to the form parameters, but nearly all ofthese are buggy.<a href="#FOOTNOTE-411">[411]</a></p><blockquote class="footnote"> <a name="FOOTNOTE-411" /><p>[411]There are some details of theinterface that these snippets don't support. Trust us;it's better to use a module.</p> </blockquote><p>When writing CGI programs, though, there are several big issues tokeep in mind. These make this topic one too broad to fully include inthis book:<a href="#FOOTNOTE-412">[412]</a></p><blockquote class="footnote"> <a name="FOOTNOTE-412" /><p>[412]Several of the reviewers who looked over adraft of this book for us wished we could cover more about CGIprogramming. We agree, but it wouldn't be fair to the reader togive just enough knowledge to be dangerous. A proper discussion ofthe problems inherent in CGI programming would probably add at least50% to the size (and cost) of this book.</p> </blockquote><dl><dt><i>Security, security, security </i></dt><dd>We can't overemphasize<a name="INDEX-1277" /><a name="INDEX-1278" />security. Somewhere around half of thesuccessful attacks on computers around the world involve asecurity-related bug in a CGI program.</p></dd></dl><dl><dt><i>Concurrency issues </i></dt><dd>It's easy to have several processes that are concurrentlytrying to access a single file or resource.</p></dd></dl><dl><dt><i>Standards compliance </i></dt><dd>No matter how hard you try, you probably won't be able to testyour program thoroughly with more than about 1 or 2% of the webbrowsers and servers that are in use today.<a href="#FOOTNOTE-413">[413]</a> That's because there are literally thousands ofdifferent programs available, with new ones popping up every week.The solution is to follow the standards, so your program will workwith all of them.<a href="#FOOTNOTE-414">[414]</a></p><blockquote class="footnote"> <a name="FOOTNOTE-413" /><p>[413]Rememberthat every new release of each brand of browser on each differentplatform counts as a new one that you're probably not going tobe able to test. We really chuckle when we hear someone tested a website with "both browsers" or when they say "Idon't know if it works with the other one."</p></blockquote><blockquote class="footnote"> <a name="FOOTNOTE-414" /><p>[414]At the very least, following thestandards lets you put the blame squarely on the other programmer,who didn't.</p> </blockquote></dd></dl><dl><dt><i>Troubleshooting and debugging </i></dt><dd>Since the CGI program runs in a different environment thanyou're likely to be able to access directly, you'll haveto learn new techniques for troubleshooting and debugging.</p></dd></dl><dl><dt><i>Security, security, security!</i></dt><dd>There, we've said it again. Don't forgetsecurity -- it's the first and last thing to think aboutwhen your program is going to be available to everyone in the worldwho wants to try breaking it.</p></dd></dl><p>And that list didn't even mention URI-encoding, HTML entities,HTTP and response codes, Secure Sockets Layer (SSL), Server-sideIncludes (SSI), here documents, creating graphics on the fly,programmatically generating HTML tables, forms, and widgets, hiddenform elements, getting and setting cookies, path info, errortrapping, redirection, taint checking, internationalization andlocalization, embedding Perl into HTML (or the other way around),working with Apache and <tt class="literal">mod_perl</tt>, and using the<tt class="literal">LWP</tt> module.<a href="#FOOTNOTE-415">[415]</a> Most or all of those topics should be covered in any goodbook on using Perl with the Web. <a name="INDEX-1279" /><em class="emphasis">CGI Programming withPerl</em> by Scott Guelich, et al. (O'Reilly &Associates, Inc.) is mighty nice here, as is Lincoln Stein's<em class="emphasis">Network Programming with Perl</em> (Addison-Wesley).</p><blockquote class="footnote"> <a name="FOOTNOTE-415" /><p>[415]Do you see why wedidn't try to fit all of that into this book?</p></blockquote><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="appb_15.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img alt="Home" border="0" src="../gifs/txthome.gif" /></a></td><td align="right" valign="top" width="228"><a href="appb_17.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">B.15. Debugging</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img alt="Book Index" border="0" src="../gifs/index.gif" /></a></td><td align="right" valign="top" width="228">B.17. Command-Line Options</td></tr></table></div><hr width="684" align="left" /><img alt="Library Navigation Links" border="0" src="../gifs/navbar.gif" usemap="#library-map" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2002</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?