The Shopping Bag Script—bag.pl

Example 3.1 is the script from Chapter 8. The script is provided mostly so that you can see how Shopping Bag works from end to end. The script works fine, but it is primitive. If you want a powerful shopping program with numerous server-side options, I suggest you seek a more robust solution.

Note

Remember that shoppers provide sensitive credit card information in the order form. If that information isn’t properly protected before it is submitted, it can easily get into the wrong hands and be used illegally. To prevent this, your web server host should support some type of protection such as Secure Sockets Layer (SSL), a protocol used for encryption. Most web server hosts support it. You should contact your web site administrator and find more information about SSL at http://webopedia.internet.com/TERM/S/SSL.html.

bag.pl has three jobs:

  1. Get all the product and customer information

  2. Save that information in a uniquely named text file on the web server

  3. Print a confirmation page to send back to the browser

Warning

Some web server hosts require that you run CGI scripts with a .cgi extension instead of a .pl extension. No biggie—just rename the file to bag.cgi. Quick recovery.

Let’s see how bag.pl takes care of all three jobs. As you look at this code, remember that you don’t have to understand the syntax. This book isn’t about Perl. Just try to follow what the code is doing from one step to the next.

Example C-1. bag.pl

 1 #!/usr/bin/perl 2 3 require "cgi-lib.pl"; ...

Get JavaScript Application Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.