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

📄 ch19_01.htm

📁 By Tom Christiansen and Nathan Torkington ISBN 1-56592-243-3 First Edition, published August 1998
💻 HTM
📖 第 1 页 / 共 2 页
字号:
CLASS="programlisting">http://mox.perl.com/cgi-bin/program</PRE><PCLASS="para">The GET and POST methods differ in another respect: <EMCLASS="emphasis">idempotency</EM><ACLASS="indexterm"NAME="ch19-idx-1000005355-0"></A>. This simply means that making a GET request for a particular URL once or multiple times should be no different. This is because the HTTP protocol definition says that a GET request may be cached by the browser, or server, or an intervening proxy. POST requests cannot be cached, because each request is independent and matters. Typically, POST requests changes or depends on the state of the server (query or update a database, send mail, or purchase a computer).</P><PCLASS="para">Most servers log requests to a file (the <EMCLASS="emphasis">access log</EM><ACLASS="indexterm"NAME="ch19-idx-1000005356-0"></A>) for later analysis by the webmaster. Error messages produced by CGI programs don't go to the browser by default. Instead they are also logged to a file (the <EMCLASS="emphasis">error log</EM><ACLASS="indexterm"NAME="ch19-idx-1000005357-0"></A><ACLASS="indexterm"NAME="ch19-idx-1000005357-1"></A><ACLASS="indexterm"NAME="ch19-idx-1000005357-2"></A>), and the browser simply gets a "500 Server Error" message saying that the CGI program didn't uphold its end of the CGI bargain.</P><PCLASS="para"><ACLASS="indexterm"NAME="ch19-idx-1000005358-0"></A><ACLASS="indexterm"NAME="ch19-idx-1000005358-1"></A>Error messages are useful in debugging any program, but they are especially so with CGI scripts. Sometimes, though, the authors of CGI programs either don't have access to the error log or don't know where it is. Having error messages sent to a more convenient location is discussed in <ACLASS="xref"HREF="ch19_03.htm"TITLE="Redirecting Error Messages">Recipe 19.2</A>. Tracking down errors is covered in <ACLASS="xref"HREF="ch19_04.htm"TITLE="Fixing a 500 Server Error">Recipe 19.3</A>.</P><PCLASS="para"><ACLASS="xref"HREF="ch19_10.htm"TITLE="Debugging the Raw HTTP Exchange">Recipe 19.9</A> shows how to learn what your browser and server are really saying to one another. Unfortunately, some browsers do not implement the HTTP specification correctly, and you can use the tools in this recipe to investigate whether your program or your browser is the cause of a problem.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch19-chap19_security_0">Security</A></H3><PCLASS="para"><ACLASS="indexterm"NAME="ch19-idx-1000005359-0"></A><ACLASS="indexterm"NAME="ch19-idx-1000005359-1"></A>CGI programs let anyone run a program on your system. Sure, you get to pick the program, but the anonymous user from Out There can send it unexpected values and try to trick it into doing the wrong thing. Thus security is a big concern on the Web.</P><PCLASS="para">Some sites address this concern by banning CGI programs. Sites that can't do without the power and utility of CGI programs must find ways to secure their CGI programs. <ACLASS="xref"HREF="ch19_05.htm"TITLE="Writing a Safe CGI Program">Recipe 19.4</A> gives a checklist of considerations for writing a secure CGI script, and it briefly covers Perl's tainting mechanism for guarding against accidental use of unsafe data. <ACLASS="xref"HREF="ch19_07.htm"TITLE="Executing Commands Without Shell Escapes">Recipe 19.6</A> shows how your CGI program can safely run other programs.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch19-chap19_html_0">HTML and Forms</A></H3><PCLASS="para"><ACLASS="indexterm"NAME="ch19-idx-1000005360-0"></A><ACLASS="indexterm"NAME="ch19-idx-1000005360-1"></A>Some HTML tags let you create forms, where the user can fill in values that will be submitted to the server. The forms are composed of widgets, like text entry fields and check boxes. CGI programs commonly return HTML, so the CGI module has helper functions to create HTML for everything from tables to form widgets.</P><PCLASS="para">In addition to <ACLASS="xref"HREF="ch19_08.htm"TITLE="Formatting Lists and Tables with HTML Shortcuts">Recipe 19.7</A>, this chapter also has <ACLASS="xref"HREF="ch19_12.htm"TITLE="Creating Sticky Widgets">Recipe 19.11</A>, which shows how to create forms that retain their values over multiple calls. <ACLASS="xref"HREF="ch19_13.htm"TITLE="Writing a Multiscreen CGI Script">Recipe 19.12</A> shows how to make a single CGI script that produces and responds to a set of pages, for example, a product catalog and ordering system.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch19-chap19_web_related_0">Web-Related Resources</A></H3><PCLASS="para"><ACLASS="indexterm"NAME="ch19-idx-1000005361-0"></A><ACLASS="indexterm"NAME="ch19-idx-1000005361-1"></A>Unsurprisingly, some of the best references on the Web are found on the Web:</P><DLCLASS="variablelist"><DTCLASS="term">WWW Security FAQ</DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="systemitem.url"HREF="http://www.w3.org/Security/Faq/">http://www.w3.org/Security/Faq/</A></P></DD><DTCLASS="term">Web FAQ</DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="systemitem.url"HREF="http://www.boutell.com/faq/">http://www.boutell.com/faq/</A></P></DD><DTCLASS="term">CGI FAQ</DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="systemitem.url"HREF="http://www.webthing.com/tutorials/cgifaq.html">http://www.webthing.com/tutorials/cgifaq.html</A></P></DD><DTCLASS="term">HTTP Specification</DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="systemitem.url"HREF="http://www.w3.org/pub/WWW/Protocols/HTTP/">http://www.w3.org/pub/WWW/Protocols/HTTP/</A></P></DD><DTCLASS="term">HTML Specification</DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="systemitem.url"HREF="http://www.w3.org/TR/REC-html40/">http://www.w3.org/TR/REC-html40/</A></P><PCLASS="para"><ACLASS="systemitem.url"HREF="http://www.w3.org/pub/WWW/MarkUp/">http://www.w3.org/pub/WWW/MarkUp/</A></P></DD><DTCLASS="term">CGI Specification</DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="systemitem.url"HREF="http://www.w3.org/CGI/">http://www.w3.org/CGI/</A></P></DD><DTCLASS="term">CGI Security FAQ</DT><DDCLASS="listitem"><PCLASS="para"><ACLASS="systemitem.url"HREF="http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt">http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt</A></P></DD></DL><PCLASS="para">We recommend Lincoln Stein's fine book, <EMCLASS="emphasis">Official Guide to Programming with Cgi.pm</EM> (John Wiley and Associates, 1998), Tom Boutell's aging but worthwhile <EMCLASS="emphasis">CGI Programming in C and Perl</EM> (Addison-Wesley, 1996) and <EMCLASS="emphasis">HTML: The Definitive Guide</EM> (3rd Edition; O'Reilly &amp; Associates, 1998) by Chuck Musciano and Bill Kennedy. The best periodical to date is the monthly <EMCLASS="emphasis">Web Techniques</EM> magazine, targeted at web programmers.</P></DIV></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="684"TITLE="footer"><TABLEWIDTH="684"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch18_10.htm"TITLE="18.9. Program: expn and vrfy"><IMGSRC="../gifs/txtpreva.gif"ALT="Previous: 18.9. Program: expn and vrfy"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><ACLASS="book"HREF="index.htm"TITLE="Perl Cookbook"><IMGSRC="../gifs/txthome.gif"ALT="Perl Cookbook"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch19_02.htm"TITLE="19.1. Writing a CGI Script"><IMGSRC="../gifs/txtnexta.gif"ALT="Next: 19.1. Writing a CGI Script"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228">18.9. Program: expn and vrfy</TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><ACLASS="index"HREF="index/index.htm"TITLE="Book Index"><IMGSRC="../gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228">19.1. Writing a CGI Script</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="684"TITLE="footer"><FONTSIZE="-1"></DIV<!-- LIBRARY NAV BAR --> <img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p> <a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -