Sams Teach Yourself E-Commerce Programming With ASP

Transcription

Stephen WaltherJonathan LevineTeach YourselfE-CommerceProgrammingwith ASPin21 DaysA Division of Macmillan USA201 West 103rd St., Indianapolis, Indiana, 46290 USA

Sams Teach Yourself E-CommerceProgramming with ASP in 21 DaysCopyright 2000 by SamsAll rights reserved. No part of this book shall be reproduced, stored in aretrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the informationcontained herein. Although every precaution has been taken in the preparationof this book, the publisher and author assume no responsibility for errors oromissions. Nor is any liability assumed for damages resulting from the use ofthe information contained herein.International Standard Book Number: 0672318989Library of Congress Catalog Card Number: 99-068489Printed in the United States of America01004Bradley L. JonesEXECUTIVE EDITORChris WebbDEVELOPMENT EDITORKevin HowardMANAGING EDITORCharlotte ClappPROJECT EDITORElizabeth RobertsCOPY EDITORRhonda Tinch-MizeINDEXERErika MillenPROOFREADERFirst Printing: April, 200002ASSOCIATE PUBLISHERJill Mazurczyk321TrademarksTECHNICAL EDITORJia WangAll terms mentioned in this book that are known to be trademarks or servicemarks have been appropriately capitalized. Sams cannot attest to the accuracyof this information. Use of a term in this book should not be regarded asaffecting the validity of any trademark or service mark.TEAM COORDINATORWarning and DisclaimerINTERIOR DESIGNEREvery effort has been made to make this book as complete and as accurate aspossible, but no warranty or fitness is implied. The information provided is onan “as is” basis. The author(s) and the publisher shall have neither liability norresponsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the CD orprograms accompanying it.Meggo BarthlowMEDIA DEVELOPERDan ScherfGary AdairCOVER DESIGNERAren HowellCOPYWRITEREric BorgertLAYOUT TECHNICIANEric S. Miller

Contents at a GlanceIntroductionWEEK 1 At a Glance15Day 1Introduction to E-Commerce7Day 2Interacting with the Customer21Day 3Using Application and Session Objects in E-Commerce Applications47Day 4Working with Files in Your E-Commerce Application69Day 5Building Your Product Catalog Database89Day 6Displaying Your Products119Day 7Searching for Products143WEEK 1 In Review163WEEK 2 At a Glance167Day 8Building the Transaction Databases169Day 9Building the Shopping Cart191Day 10Checking Out213Day 11Working with Credit Cards237Day 12Letting Customers Track Their Orders259Day 13Creating a Subscription-Based Site273Day 14Customizing the Shopping Experience297WEEK 2 In Review319WEEK 3 At a Glance323Day 15Securing Your Store325Day 16Debugging Your E-Commerce Applications345Day 17Administering Your Store Remotely with ASPs377Day 18Using Email from Active Server Pages409Day 19Generating Store Reports441

Day 20Working with Wallets467Day 21Promoting Your Site and Managing Banner Advertising495WEEK 3 In Review519Appendix AQuiz Answers523Appendix BFrequently Asked Questions About Active Server Pages545Appendix CSQL Reference559Index571

ContentsIntroductionWEEK 1 At A GlanceDAY 1 Introduction to E-Commerce157What Is E-Commerce? .8Microsoft Technologies for E-Commerce .9Microsoft Personal Web Server .10Microsoft Internet Information Server .10Microsoft Access .11Microsoft SQL Server .11Microsoft Visual InterDev .12What Is an ASP Page? .13Active Server Pages Contain Scripts .14Active Server Pages Contain Objects and Components .15Active Server Pages and Database Access .17Summary .17Q&A .18Workshop .18Quiz .18DAY 2 Interacting with the Customer21Working with the Response Object .22Outputting Long Strings .23Displaying Special Characters .23Displaying Quotation Marks .24Using the % and % Output Delimiters .26Ending Script Execution with the Response Object .26Working with the Request Object .27Using Query Strings .28Using the Form Collection .31Retrieving Query String and Form Variables .38Working with Server Variables .39Retrieving the Customer’s Internet Address .41Summary .43Q&A .43Workshop .44Quiz .44Exercise .45

viSams Teach Yourself E-Commerce Programming with ASP in 21 DaysDAY 3 Using Application and Session Objects in E-CommerceApplications47Tracking Customers with Cookies .48Adding a Cookie to a Customer’s Browser .50Reading Cookies from a Customer’s Browser .51Tracking Customers with Session Variables .52Storing Arrays in Session Variables .54Tracking a Session with a SessionID .56Ending a User Session .56Using Application Variables .57Storing Arrays in Application Variables .60Removing Application Variables From Memory .61Using the Global.asa File .62Summary .65Q&A .66Workshop .67Quiz .67Exercise .68DAY 4 Working with Files in Your E-Commerce Application69Including Files in an ASP Page .69Dynamically Including Files .73Using File Redirection .75Using the File Access Component .77Managing Text Files .81Displaying the Contents of a Folder .83Sample Application: Recording Marketing Data .84Summary .85Q&A .86Workshop .86Quiz .87Exercise .87DAY 5 Building Your Product Catalog89Creating the Store Database .89Creating the Products Table .91Connecting to a Database .93Adding Products to the Products Table .95Creating the AddProducts Form .97A Problem with Databases and Quotation Marks .102Updating Product Information in the Products Table .104Displaying the List of Products to Update .106Creating the updateProduct Form .109

ContentsviiA Problem with HTML Forms and Quotation Marks .112Updating a Database Record .113Summary .117Q&A .117Workshop .118Quiz .118Exercises .118DAY 6 Displaying Your Products119Using Recordsets .119Using the SQL SELECT Statement .121Recordset Cursor Types .122Displaying Products .123Selecting Product Categories .125Displaying the List of Products .126Creating the Main Store Page .128Displaying Product Details .130Paging Through A Recordset .134Making Your Store More Scalable .137Summary .140Q&A .140Workshop .140Quiz .140Exercise .141DAY 7 Searching for Products143Displaying a Rotating List of Featured Products .143Selecting the List of Featured Products .144Retrieving the List of Featured Products .146Optimizing the Display of Featured Products .149Creating a Search Page .152Optimizing the Search Page .157Creating Indexable Web Pages .158Summary .160Q&A .160Workshop .160Quiz .160Exercise .161WEEK 1 In Review163Bonus Project .163Creating a Customer Feedback Form .163

viiiSams Teach Yourself E-Commerce Programming with ASP in 21 DaysWEEK 2 At A GlanceDAY 8 Building the Transaction Databases167169The Transaction Database Tables .170Creating the Users Database Table .171Registering Users .172Creating the cart.asp Page .172Creating the register.asp Page .174The Registration Functions .176Gracefully Handling Form Errors .181Using the Secure Sockets Layer .183Enabling SSL on Your Web Server .185Applying for a Server Certificate .186Installing Your Server Certificate .187Using SSL in an ASP Page .187Summary .188Q&A .189Workshop .189Quiz .189Exercise .190DAY 9 Building the Shopping Cart191Using Session Variables to Createa Shopping Cart .191Creating the SessionCart.asp Page .193Using Native ADO Methods .200Creating Updateable Recordsets .200Adding New Records with AddNew .201Updating Existing Records .202Deleting Records with Delete .203Using a Database Table to Createa Shopping Cart .204Creating the addCart.asp Page .206Summary .211Q&A .211Workshop .212Quiz .212Exercise .212DAY 10 Checking Out213Understanding Transactions .213ASP Page Transactions .214ADO Transactions .218Database Transactions .219

ContentsixCompleting the Order .219Retrieving Address and Payment Information .220Updating Address and Payment Information .221Transferring the Shopping Cart .224Processing Orders .226Summary .234Q&A .234Workshop .235Quiz .235Exercises .235DAY 11 Working with Credit Cards237Methods of Processing Credit Cards .237Offsite Payment Processors .238Payment Terminal Solutions .239Component-Based Solutions .239Choosing a Method of Processing Credit Cards .240Preparing for CyberCash .240Opening a Credit Card Merchant Account .241Registering at CyberCash .242Installing the CyberCash Software .243Authorizing a Credit Card Transaction .245Integrating the Authorization Script into Your Store .248Settling Credit Card Transactions .254Summary .256Q&A .256Workshop .257Quiz .257DAY 12 Letting Customers Track Their Orders259Enabling Customers to Track Orders with a Web Page .260Calculating Shipping Costs .264Installing the iisCARTship Component .265iisCARTship Properties and Methods .265iisCARTship Component Sample Application .269Summary .271Q&A .272Workshop .272Quiz .272DAY 13 Creating a Subscription-Based Site273Using HTTP Authentication .274Enabling HTTP Authentication .275When You Should Use HTTP Authentication .276

xSams Teach Yourself E-Commerce Programming with ASP in 21 DaysUsing Database Authentication .276Passing Security Information From Page to Page .285Using Hybrid Authentication .287Understanding How Basic Authentication Works .288Forcing a Password Dialog to Appear .288Decoding the AUTHORIZATION Header .290Summary .294Q&A .295Workshop .295Quiz .295DAY 14 Customizing the Shopping Experience297Retrieving the Existing User Settings .297Creating mypage.asp .298Showing Past Purchases .302Advertising Items Your Customers Would Like .307Updating the Users Table for Favorites .307Building the favorites.asp Page .308Building the savefavorites.asp Page .311Updating the featured.asp Page .313Updating the default.asp Page .315Summary .316Q&A .316Workshop .317Quiz .317Exercise .317WEEK 2 In Review319Bonus Project .320Creating a Transactional Customer Feedback Form .320WEEK 3 At A GlanceDAY 15 Securing Your Store323325Registering Your Own Domain .326Domain Names and Marketing .326Registering Your Domain Name Yourself .327Making Your Server More Secure .329Use NT Server or Windows 2000 Server, not NT Workstationor Windows 2000 Professional .329Make Sure That the Latest Service Packs and Hotfixes Are Appliedto Your System .330Change the Name and Password of Your System’s AdministratorAccount .331

ContentsxiUse NTFS .332Use a Firewall .334Keep Your Server Locked Up .334Keep Your Server Running .335Protecting Your Users’ Private Information with SSL .335Protecting Your Database .337Registering with the Better Business Bureau Reliability Program .338Establishing a Privacy Policy and Joining a Privacy Seal Program .339The Better Business Bureau’s Children’s Advertising Review UnitGuidelines .341Summary .342Q&A .343Workshop .343Quiz .343Exercise .343DAY 16 Debugging Your E-Commerce Applications345Keeping Your Development and Production Systems Separate .346Creating a Second IP Address .347Creating a Second Web Site .349Deploying Your Application Using Visual InterDev .350Debugging Your Application Using Visual InterDev’s Integrated Debugger .354Getting Ready to Debug .355Debugging a Site .357Debugging Your Application on a Production Server .361Creating and Maintaining a Session Variable for Debugging .362Using the Session-level Debugging Variable .364Creating a Debug Library .366Recovering from and Capturing Errors .366Capturing E

Day 1 Introduction to E-Commerce 7 Day 2 Interacting with the Customer 21 Day 3 Using Application and Session Objects in E-Commerce Applications 47 Day 4 Working with Files in Your E-Commerce Application 69 Day 5 Building Your Product Catalog Database 89 Day 6 Displaying Your Products