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

📄 ch13.htm

📁 Web_Programming_with_Perl5,一个不错的Perl语言教程。
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">



<HTML>







<HEAD>



<!-- This document was created from RTF source by rtftohtml version 3.0.1 -->







	<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">



	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">



	<TITLE>Without a title - Title</TITLE>



</HEAD>







<BODY BACKGROUND="r2harch.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/r2harch.gif" TEXT="#000000" BGCOLOR="#FFFFFF">







<H2 ALIGN="CENTER"><A HREF="ch12.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch12.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="ch14.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch14.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><BR>



<BR>



<BR>



<FONT COLOR="#0000AA">13</FONT><BR>



<A NAME="Heading1"></A><FONT COLOR="#000077">Shopping Cart Applications<BR>



</FONT>



<HR>



</H2>







<UL>



	<LI><A HREF="#Heading1">Shopping Cart Applications</A>



	<UL>



		<LI><A HREF="#Heading2">Implementation Issues</A>



		<UL>



			<LI><A HREF="#Heading3">Maintaining a Persistent State</A>



			<LI><A HREF="#Heading4">Dynamic Generation of Forms</A>



			<LI><A HREF="#Heading5">Database Issues</A>



			<LI><A HREF="#Heading6">Security</A>



		</UL>



		<LI><A HREF="#Heading7">MiniVend Package</A>



		<LI><A HREF="#Heading8">Installation and Configuration</A>



		<LI><A HREF="#Heading9">Overview of Features</A>



		<LI><A HREF="#Heading10">Use and Customization</A>



		<UL>



			<LI><A HREF="#Heading11">Setting Up Your Product Catalog</A>



			<LI><A HREF="#Heading12">Setting Up Your minivend.cfg File</A>



			<LI><A HREF="#Heading13">Setting Up Your Catalog Pages</A>



		</UL>



		<LI><A HREF="#Heading14">Listing 13.1. The main catalog page.</A>



		<UL>



			<LI><A HREF="#Heading15">Setting Up Your Search Pages</A>



		</UL>



		<LI><A HREF="#Heading16">Listing 13.2. The search page.</A>



		<LI><A HREF="#Heading17">Listing 13.3. The browse page.</A>



		<UL>



			<LI><A HREF="#Heading18">Displaying Search Results</A>



		</UL>



		<LI><A HREF="#Heading19">Listing 13.4. The results display page.</A>



		<UL>



			<LI><A HREF="#Heading20">Setting Up Your Order Page</A>



		</UL>



		<LI><A HREF="#Heading21">Listing 13.5. The order page.</A>



		<UL>



			<LI><A HREF="#Heading22">Other Pages to Complete Your Site</A>



			<LI><A HREF="#Heading23">Frames</A>



			<LI><A HREF="#Heading24">Additional Tools for Administration of Your Site</A>



		</UL>



		<LI><A HREF="#Heading25">A Few Words About Security</A>



		<LI><A HREF="#Heading26">Summary</A>



	</UL>



</UL>







<P>



<HR>



</P>







<UL>



	<LI>Implementation Issues



	<P>



	<LI>MiniVend Package



	<P>



	<LI>Installation and Configuration



	<P>



	<LI>Overview of Features



	<P>



	<LI>Use and Customization



	<P>



	<LI>A Few Words About Security



</UL>







<P>The idea of shopping on the World Wide Web is an intriguing one. Imagine the convenience



of purchasing items with a simple point-and-click operation. This chapter covers



the details of what are called shopping cart applications. It also describes the



MiniVend package, which was written by Mike Heins and based on the Vend package written



by Andrew Wilcox.



<H3 ALIGN="CENTER"><A NAME="Heading2"></A><FONT COLOR="#000077">Implementation Issues</FONT></H3>



<P>Several issues need discussion before diving right into the example. I first describe



a few basic problems with CGI and the ways around these problems. I also describe



some of the advantages of CGI over static HTML pages. Of course, security is of major



concern, especially when talking about Internet commerce. I attempt to address some



of these issues and then analyze the MiniVend package and how you can use it to set



up your virtual store quickly.



<H4 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">Maintaining a Persistent



State</FONT></H4>



<P>One of the biggest drawbacks of HTTP and CGI is the lack of a persistent state.



The nature of the HTTP protocol is such that each request made on a server is a separate



and distinct connection that ends when the server responds with a result. This approach



is perfect for the concept of surfing the Web but not so perfect for the concept



of a session consisting of multiple requests. When you're shopping for an item at



a Web site, you most likely want to &quot;surf &quot; around in the site's product



catalogs and choose what you want to buy as you're going along. Doing so requires



<BR>



several separate and distinct requests from the browser to the server. However, you



still want to maintain information such as the products selected, the running subtotal,



and so on.</P>



<P>This lack of a persistent state can be solved in a few different ways. One way



is to use hidden form fields (see Chapter 5, &quot;Putting It All Together&quot;).



Another is for the server to keep some file <BR>



associated with the session for the duration of the session. Yet another is to use



what are known as cookies; this approach is a client-based persistence solution.



<H4 ALIGN="CENTER"><A NAME="Heading4"></A><FONT COLOR="#000077">Dynamic Generation



of Forms</FONT></H4>



<P>One of the major strengths of the CGI approach over static HTML is, of course,



the ability to dynamically generate the contents of a page. The best approach to



setting up a list of products for sale is to define a database that contains the



product information such as the price, whether it's in stock, and a brief description



of the item. Because this information is dynamic, you want the ability to generate



your pages based on the current state of your products. If something is out of stock,



you would like to be able to tell the shoppers and provide them with an estimated



date of when it may be available again.</P>



<P>Rather than constantly update static HTML pages with this information, it makes



much more sense to store the information in a database and have a script retrieve



the information and generate the pages on request. After all, dynamic content retrieval



is one of the intents of CGI, and Perl is one of the best languages for doing this



type of work. Several database modules that work using standard ASCII formatted files



are available with Perl. You see one of these database interfaces in the MiniVend



example. Another strength of Perl is the powerful regular expression capabilities



for reformatting text and global substitution of strings.



<H4 ALIGN="CENTER"><A NAME="Heading5"></A><FONT COLOR="#000077">Database Issues</FONT></H4>



<P>I've already touched briefly on the need for storing information in a database.



The database interface modules available in Perl are a good start. As your product



inventory grows, you may want to store your data in a large commercial relational



database. Other database modules are available for Perl to use with some of the popular



database systems.



<H4 ALIGN="CENTER"><A NAME="Heading6"></A><FONT COLOR="#000077">Security</FONT></H4>



<P>Last but certainly not least among the implementation issues is the issue of security.



The standard HTTP protocol does not define any means of encryption and decryption



when transferring data. You may have seen a dialog box in your browser warning you



of this situation whenever you press a Submit button in a form. This warning essentially



tells you that, when you send this data through the Net, anyone can see the data



that you are transmitting. This lack of security can lead to a lot of worries when



that data includes your credit card number and other personal information about yourself.</P>



<P>One solution to this security problem is Netscape's Secure Socket Layer (SSL)



protocol. This protocol is discussed briefly in Chapter 3, &quot;Security on the



Web.&quot; You can also find more information on this at Netscape's Web site with



the following URL:</P>



<PRE><FONT COLOR="#0066FF">http://home.netscape.com/comprod/server_central/config/secure.html



</FONT></PRE>



<P>I strongly suggest that anyone setting up an electronic store should thoroughly



understand where the holes are and how to prevent surreptitious use of your and your



customer's data.</P>



<P>The MiniVend package addresses the issue of security in several ways. You look



more deeply into this important issue at the end of the example.



<H3 ALIGN="CENTER"><A NAME="Heading7"></A><FONT COLOR="#000077">MiniVend Package</FONT></H3>



<P>MiniVend, a package available through the Perl CPAN, enables you to set up an



electronic store easily. Mike Heins developed the package based on Vend from Andrew



Wilcox. Some of its features (direct from the MiniVend README file) are as follow:







<UL>



	<LI>Users maintain a &quot;shopping cart&quot; for ordered items.



	<P>



	<LI>SSL support means secure and practical credit card ordering.



	<P>



	<LI>Catalogs can be of almost unlimited size with excellent performance.



	<P>



	<LI>It provides a powerful search capability, including a complete Glimpse interface,



	<BR>



	one-click search profile capability, and independent field-search selection.



	<P>



	<LI>It provides multi-server mode for very high capacity on systems with sufficient



	memory.



	<P>



	<LI>It provides forked searches for consistent response time in single-server mode.



	<P>



	<LI>Cookie support allows browsers to leave a catalog and come back without losing



	the session state.



	<P>



	<LI>It provides full frames support.



	<P>



	<LI>Catalog pages are automatically selected--either built &quot;on the fly&quot;



	from the database or premade for popular items.



	<P>



	<LI>It works well with all browsers.



	<P>



	<LI>It provides complete addressable database support with virtually unlimited rows



	and columns.



	<P>



	<LI>It provides fully configurable quantity pricing.



	<P>



	<LI>It provides easy back-end order entry.



	<P>



	<LI>It provides full client-side imagemap support, including frame targets and form



	submits.



	<P>



	<LI>It provides automatic installation and configuration.



	<P>



	<LI>It provides remote administration via the Web using mat.



	<P>



	<LI>It runs under Perl5 and almost any UNIX platform.



	<P>



	<LI>It is designed to be secure and runs with taint checking enabled.



	<P>



	<LI>It includes a built-in online help capability.



	<P>



	<LI>It calculates sales tax, with fully independent nontaxable item and taxed shipping.



	<P>



	<LI>It calculates shipping (quantity and/or weight).



</UL>







<P>In the following sections, I explain how to install and configure the MiniVend



package on <BR>



your system and emphasize the importance of some of the features in the preceding



list. You can find complete and up-to-date information on this package in the CPAN



as well as at the following URL:</P>



<PRE><FONT COLOR="#0066FF">http://www.iac.net/~mikeh/download.html



</FONT></PRE>



<H3 ALIGN="CENTER"><A NAME="Heading8"></A><FONT COLOR="#000077">Installation and



Configuration</FONT></H3>



<P>Installation of the MiniVend package is simple. First download the mvend103.tar.gz



file to a new directory, and then run the following commands:</P>



<PRE><FONT COLOR="#0066FF">gzip -d mvend103.tar.gz



tar -xvf mvend103.tar



</FONT></PRE>



<P>Fortunately, Mike has made it easy for you to configure the package for your Web



server as well. Before you begin the configuration process, you must obtain the following



information:







<UL>



	<LI>The directory of your server's document root. The default value with NCSA and



	Apache is /usr/local/etc/httpd/htdocs.



	<P>



	<LI>The directory of your server's CGI executables. The default value with NCSA and



	Apache is /usr/local/etc/httpd/cgi-bin.



	<P>

⌨️ 快捷键说明

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