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

📄 ch16.htm

📁 Web_Programming_with_Perl5,一个不错的Perl语言教程。
💻 HTM
📖 第 1 页 / 共 3 页
字号:
   print "<STRONG>Sorry! You are not authorized to enter this area!</STRONG><BR>\n";



   print "<A HREF=/cgi-bin/cmdshell.pl>Try again</A>";



}







sub loginForm {



   my($q)=@_;



   print "<P>Please enter your userid and password:<P>\n";



   print $q->start_multipart_form();



   print $q->textfield(-name=>`uid');



   print "<BR>";



   print $q->password_field(-name=>`pw');



   print "<BR>";



   print $q->submit(-name=>`Action',-value=>`Login');



   print $q->reset;



   print $q->endform;



}







sub shellForm {



   my($q,$history)=@_;



   print $q->start_multipart_form();



   print $q->hidden(-name=>`cmdHistory',-value=>$history);



   print $q->textfield(-name=>`command');



   print "<BR>";



   print $q->submit(-name=>`Action',-value=>`Doit');



   print " ";



   print $q->reset;



   print $q->endform;



   print "<P>Command History:<P>\n";



   print "<PRE>$history<\PRE>";



}







sub doCommand {



   my($q,$cmd)=@_;



   my($hist)="$cmd\n";



   $hist.=`$cmd`;



   return "$hist\n";



}



</FONT></PRE>



<P>You can see how the login form would look in Figure 16.3. Once the user has logged



in and issued a few commands, the shell would look as shown in Figure 16.4. <BR>



<BR>



<A HREF="18wpp03.jpg" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/18wpp03.jpg"><TT><B>Figure 16.3.</B></TT></A><TT> </TT>The command



shell login form.<BR>



<BR>



<A HREF="18wpp04.jpg" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/18wpp04.jpg"><TT><B>Figure 16.4.</B></TT></A><TT> </TT>The command



shell with history. <BR>



<BR>



You will notice in this example that we keep a running history of command output.



When the output exceeds a certain limit, in this case 1,024 characters, it will be



truncated. The session is maintained as long as continuous <TT>POST</TT> requests



are made. As soon as the user leaves this CGI session, it will reinitialize on the



<TT>GET</TT> request.



<H4 ALIGN="CENTER"><A NAME="Heading7"></A><FONT COLOR="#000077">Warning and Dangers



of Multiple Persistent Servers</FONT></H4>



<P>It is very important that you understand the impact that your CGI scripts can



have on your server's resources. Remember that, on most servers, for each CGI request,



a new process is spawned to handle that request. There are a few servers that will



allow you to embed CGI invocations as function calls from within the server.</P>



<P>You must also consider the possibility of colliding clients when trying to define



how a session is maintained. There are certain basic parameters that can be used



to distinguish sessions. Our example used the <TT>REMOTE_ADDR</TT> environment variable,



which is good to separate clients from one another. You may also wish to create multiple



sessions along a given client in which case you could throw in another variable such



as time.



<H3 ALIGN="CENTER"><A NAME="Heading8"></A><FONT COLOR="#000077">Embedded ObjectsAn



Internet Proposal</FONT></H3>



<P>HTML is an evolving standard. As more and more people access information on the



World Wide Web, we find more limitations on the original HTML specification. There



are plenty of new proposals for adding functionality to the HTML language. One of



these proposals addresses the ability to embed generic objects into an HTML document.



These generic objects include such things as Java applets, Microsoft ActiveX controls,



and documents and other multimedia objects. This new tag is the <TT>&lt;OBJECT&gt;</TT>



tag, and it allows HTML authors to provide richer content for those browsers that



support the newer document types.</P>



<P>The <TT>&lt;OBJECT&gt;</TT> tag has been designed in such a way that it will include



support for many different types of embeddable objects. The first parameter is <TT>ID</TT>,



which can be used to give the object a unique identifier for hypertext links. The



<TT>CLASSID</TT> parameter specifies an implementation for the object. <TT>CODEBASE</TT>



allows for an additional URL to be specified for the object's implementation. <TT>DATA</TT>



and <TT>TYPE</TT> are used to specify the object's data and media type. <TT>CODETYPE</TT>



is similar to <TT>TYPE</TT>, except that it refers to the type of data pointed to



by <TT>CODEBASE</TT>. <TT>STANDBY</TT> allows you to specify a text string that is



displayed by the browser while the data is being loaded. This tag also contains parameters



for appearance and alignment such as <TT>ALIGN</TT>, <TT>WIDTH</TT>, <TT>HEIGHT</TT>,



<TT>BORDER</TT>, <TT>HSPACE</TT>, and <TT>VSPACE</TT>. The <TT>NAME</TT> parameter



allows the object's data to be included in the contents of a form if the <TT>&lt;OBJECT&gt;</TT>



element is found within the <TT>&lt;FORM&gt;</TT> block.</P>



<P>One example of something that might use the <TT>&lt;OBJECT&gt;</TT> tag is a Java



applet. Here is how the object would be placed within the HTML code.</P>



<PRE><FONT COLOR="#0066FF">&lt;OBJECT CLASSID=&quot;java:myproduct.myclass&quot; HEIGHT=100 WIDTH=100&gt;



Sorry, this browser cannot execute Java applets.



&lt;/OBJECT&gt;



</FONT></PRE>



<P>The text within the <TT>&lt;OBJECT&gt;</TT> block is displayed if the Java applet



cannot be executed in the browser. This might be a good place to put a hypertext



link to the Web site where one can download a plug-in to handle the type of object



you are trying to display. For example, here is an object reference to a PDF document:</P>



<PRE><FONT COLOR="#0066FF">&lt;OBJECT data=mydoc.pdf TYPE=&quot;application/pdf&quot; HEIGHT=200 WIDTH=100&gt;



&lt;A HREF=http://www.adobe.com&gt;Works best with the Acrobat plug-in&lt;/A&gt;



&lt;/OBJECT&gt;



</FONT></PRE>



<H3 ALIGN="CENTER"><A NAME="Heading9"></A><FONT COLOR="#000077">Netscape Cookies



and Other Netscape Feature Tags</FONT></H3>



<P>Netscape Navigator 1.1 and later support a feature called cookies. Cookies provide



the capability to maintain session information on the client end. Cookies are essentially



little bits of information that are stored on the client's local disk and then may



be obtained by a CGI program for future use. Cookies provide a better way to store



persistent session information for individual clients. Server maintained files can



become unruly as more clients are managed. It makes sense that client-specific information



be stored at the client. There is a function in the CGI.pm module that provides a



simple callable interface for access to these cookies.</P>



<P>The way to create a cookie is by using the <TT>cookie()</TT> method and then passing



the cookie created by that method to the <TT>header()</TT> method to be incorporated



into the document header. You can then access the cookie by just passing the <TT>-name</TT>



argument without the <TT>-value</TT> argument. Here is an example of how to create



a cookie as part of your document:</P>



<PRE><FONT COLOR="#0066FF">$cookie=$q-&gt;cookie(-name=&gt;`Userid',-value=&gt;`bdeng',-expires=&gt;&quot;+1h&quot;,



                  -path=&gt;&quot;/cgi-bin&quot;);



print $q-&gt;header(-cookie=&gt;$cookie);



</FONT></PRE>



<P>This creates a cookie called <TT>Userid</TT>, which is set to <TT>bdeng</TT> and



expires one hour from the time it is created. This cookie will also be valid only



for documents that begin with the partial path of <BR>



/cgi-bin. Later, when a program in the /cgi-bin path is called, it can query the



value of the <TT>Userid</TT> cookie by calling the cookie method with <TT>-name=&gt;`Userid'</TT>.



At the time of this writing, this capability existed only in the <TT>CGI.pm</TT>



module and not in the CGI modules contained within the LWP modules.</P>



<P>Another feature of Netscape that other browsers are beginning to adopt is that



of frames. You can create a page with multiple frames where each frame refers to



a separate URL. You can then target these frames with links from the other frames.



This provides the user with a nice uniform way of navigating through a site without



having to jump all over the place. Frame support is also available in the <TT>CGI.pm</TT>



module as part of the <TT>header()</TT> and <TT>start_form()</TT> methods. These



methods both support the parameter <TT>-target</TT> where you can specify a target



frame for displaying the document or form.



<H3 ALIGN="CENTER"><A NAME="Heading10"></A><FONT COLOR="#000077">Summary</FONT></H3>



<P>This chapter touched on some of the more advanced issues surrounding CGI programming



and HTML markup. If you are interested in learning more about the CGI specification



and what it is capable of, a good starting point would be the NCSA Web site at the



following URL:</P>



<PRE><A HREF="javascript:if(confirm('http://hoohoo.ncsa.uiuc.edu/cgi/interface.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://hoohoo.ncsa.uiuc.edu/cgi/interface.html'" tppabs="http://hoohoo.ncsa.uiuc.edu/cgi/interface.html"><FONT COLOR="#0066FF">http://hoohoo.ncsa.uiuc.edu/cgi/interface.html</FONT></A><FONT



COLOR="#0066FF">



</FONT></PRE>



<P>The most important issue you will probably face with respect to CGI programming



is that of maintaining a persistent state across transactions. The examples provided



in this chapter should help you in understanding solutions to that problem.</P>



<P>The best reference for the evolving HTML specification is at the W3C Web site



at the follow-<BR>



ing URL:</P>



<P><A HREF="javascript:if(confirm('http://www.w3.org/pub/WWW/MarkUp/MarkUp.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.w3.org/pub/WWW/MarkUp/MarkUp.html'" tppabs="http://www.w3.org/pub/WWW/MarkUp/MarkUp.html"><TT>http://www.w3.org/pub/WWW/MarkUp/MarkUp.html</TT></A><TT></TT></P>



<P>You might also like to keep up to date with the specific features provided by



Netscape Navigator and Microsoft Internet Explorer. Netscape Navigator specifics



can be found at the following URL:</P>



<PRE><A HREF="javascript:if(confirm('http://developer.netscape.com/library/documentation/htmlguide/index.htm  \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://developer.netscape.com/library/documentation/htmlguide/index.htm'" tppabs="http://developer.netscape.com/library/documentation/htmlguide/index.htm"><FONT



COLOR="#0066FF">http://developer.netscape.com/library/documentation/htmlguide/index.htm</FONT></A><FONT



COLOR="#0066FF">



</FONT></PRE>



<P>Microsoft Internet Explorer specifics can be found at this URL:</P>



<PRE><A HREF="javascript:if(confirm('http://www.microsoft.com/intdev/prog-gen/webpage.htm  \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.microsoft.com/intdev/prog-gen/webpage.htm'" tppabs="http://www.microsoft.com/intdev/prog-gen/webpage.htm"><FONT COLOR="#0066FF">http://www.microsoft.com/intdev/prog-gen/webpage.htm</FONT></A><FONT



COLOR="#0066FF">



</FONT></PRE>



<PRE ALIGN="CENTER"><A HREF="ch15.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch15.htm"><IMG SRC="blanprev.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blanprev.gif" WIDTH="37" HEIGHT="37"



ALIGN="BOTTOM" BORDER="2"></A><A HREF="index-1.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/index-1.htm"><IMG SRC="blantoc.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blantoc.gif" WIDTH="42"



HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A><A HREF="appa.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/appa.htm"><IMG SRC="blannext.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blannext.gif"



WIDTH="45" HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A></PRE>











</BODY>







</HTML>

⌨️ 快捷键说明

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