Home > Store

Writing CGI Applications with Perl

Register your product to gain access to bonus material or receive a coupon.

Writing CGI Applications with Perl

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2001
  • Dimensions: 7-3/8" x 9-1/4"
  • Pages: 560
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-71014-5
  • ISBN-13: 978-0-201-71014-4

Writing CGI Applications with Perl is a start-to-finish guide to accomplishing key Web development tasks by fully using the power of Perl and CGI together. Using extensive examples, careful line-by-line explanations, and skill-stretching exercises, it not only provides useful cut-and-paste code: it also teaches the practical skills and techniques you'll need to build virtually any CGI-based application. Kevin Meltzer and Brent Michalski cover every key area of Web application development with Perl: database integration, form and file handling, security, e-mail, graphics, and more. The book's in-depth coverage includes: working with HTML Web forms and obtaining user input; placing cookies and tracking clicks; connecting to POP3 e-mail servers; embedding Perl in HTML using HTML::Mason; remote file management across the Web; creating dynamic images; and working with XML. The book also provides detailed explanations and examples of working with Perl DBI, as well as start-to-finish coverage of configuring and using the popular mod_perl Apache module. All of the sample code will be available at a companion web site.

Downloads

Source Code

Source Code

source code

Sample Content

Downloadable Sample Chapter

Click below for Sample Chapter related to this title:
chapter16.pdf

Table of Contents



Foreword.


Preface.


Acknowledgments.


1. Perl, CGI, and this Book.

What Is Perl?

What Is CGI?

Why Perl Is Good for CGI.

About this Book.

Who Is this Book For?

Conventions Used in this Book.

Using perldoc.

Using the CPAN.



2. What You Should Know.

Prerequisites.

Editors.

File Permissions.

Basic Security Concerns.

Using -T.

Checking for Taintedness and Laundering Data.

Your PATH and -T.

Installing a Script.

Troubleshooting.

Caching.

The Expires HTTP Header.

Cache-Control HTTP Header.

Listings.



3. Using Your Environment.

Introduction to %ENV.

Adding to %ENV.

Form Input Primer.

Example Script: Visitor Log.

Example Script: Basic Report.

Reader Exercise.

What Have We Learned?

Listings.



4. Introduction to Web Forms.

Introduction.

Form Tags.

Reading Form Input with CGI.pm.

Making Your Users Happy.

Final Example.

User Exercises.

Program Listings.



5. Working with Cookies.

Introduction.

Security.

Limitations.

Cookie Pieces.

Working with Cookies the Manual Way.

Baking Cookies with CGI.pm.

Controlling User Preferences with Cookies.

User Exercises.



6. Access Counters.

Introduction.

Example Script: SSI Text Counter.

Example Script: SSI Image Counter.

Example Script: SSI Text Counter, with a Twist.

Example Script: An Imageless Image Counter.

Counter Conclusion.

Reader Exercises.

Listings.



7. Web-Based File Uploading.

Introduction.

File Uploading Basics.

Viewing Files.

Uploading Multiple Files.

Reader Exercises.

File Listings.



8. Tracking Clicks.

Introduction.

Example Script: A Simple Click Tracker.

Example Script: Random Images.

Example Script: Click Tracking (Reprise).

Reader Exercises.

Listings.



9. Using mod_perl.

What Is mod_perl?

Configuring mod_perl.

Apache::Registry.

Automatic Headers and Footers with Apache::Sandwich.

A mod_perl Photo Album with Apache::Album.

Authentication with Apache::AuthDBI.

Writing a mod_perl Handler.

Reader Exercises.

Listings.



10. Web-Based E-mail.

Introduction.

Example Script: Checking POP3 Mail via the Web.

Example Script: Reading E-mail via the Web.

Example Script: Displaying Attachments.

Example Script: Composing E-mail.

Reader Exercises.

Listings.



11. Introduction to DBI and Databases on the Web.

Introduction.

Using the Perl DBI.

Connecting to the Database.

Disconnecting from the Database.

Preparing and Executing an SQL Query.

Fetching Data.

The fetchall_arrayref( ) Method.

The fetchrow_arrayref( ) Method.

The fetchrow_hashref( ) Method.

The bind_columns( ) Method.

Putting It All Together.

The do( ) Method.

Wrapping It Up.

Reader Exercises.

Listings.



12. Tied Variables.

Introduction.

Setting It All Up.

Getting Started.

Diving In.

The Main Program.

Finishing the ShopCart Module.

Running the Program.

Wrapping It Up.

Program Listings.



13. Embedding Perl in HTML with Mason.

Introduction.

Installation.

The Strategy.

Mason Syntax.

Special Mason Components.

Cascading Execution.

Moving Right Along.

rss2html.

my_news.

footer.

Wrapping It Up: The Code for the Example Site.



14. Document Management via the Web.

Introduction.

The Plan.

auth.cgi.

shared.pl.

main.cgi.

upload.cgi.

viewer.cgi.

Program Listings.



15. Dynamically Manipulating Images.

Introduction.

Adding Shapes and Text.

Creating a Dynamic Graph.

Creating Thumbnail Images.

Filtering Images with Image::Magick.

Animated Images.

Reader Exercises.

Listings.



16. RSS And XML.

XML and RSS Overview.

Structure of an XML Document.

News Portals with RSS.

A Home Page News Portal.

Creating an RSS File.

Reader Exercises.

Listings.



Appendix A. Server Codes.

Provide confirmation that a request is being processed.

Request was performed.

Request not performed.

Request is incomplete.

Internal server errors.



Appendix B. Environment Variables.


Appendix C. POSIX::strftime( ) Formats.


Appendix D. General Public License.


Appendix E. Artistic License.


Appendix F. Perl Documentation.


Appendix G. ASCII Codes.


Appendix H. Special HTML Characters.


Resources.


Index. 0201710145T04062001

Preface

Purpose of this Book

Perl's popularity as a CGI scripting language is growing by leaps and bounds. However, there are few books available today that cover this subject in depth including a broad range of concepts. We wanted our book to help people learn to use Perl and convince them that it is the best choice for their Web-based applications. The goal of this book is not to teach the Perl language--although certain tricks and features may be learned--but to show how Perl can accomplish the tasks needed for many of today's online applications. In short, we wanted to provide a resource that not only teaches new uses of Perl but challenges the reader with exercises that use the concepts. Standard Perl documentation is also provided. The book covers a wide range of concepts, and using these, you should be able to write almost any Perl/CGI application with the techniques provided.

This book is different from others about Perl and CGI. It takes a cumulative approach and introduces applications that use concepts learned in previous chapters. Each chapter will cover at least one specific Web-based application and explain the code line by line (or block by block) so you not only learn what the scripts are doing but how they are doing it. And in order to help induce self-learning and application building, each application is working but incomplete. We provide skeleton applications that can stand on their own, but we leave out certain features that can be added (and we suggest adding them in the exercises) using the information in that chapter and in previous chapters. Our goal is not to give you "cut and paste" software but rather to show you how to write the software yourself.

Chapter Summaries

Chapter 1, Perl, CGI, and this Book. This chapter explains what Perl and CGI are. It also supplies more detail about this book and shows how to use the CPAN module.

Chapter 2, What You Should Know. We don't expect the reader to know everything, but we do expect at least a base level of knowledge. This chapter outlines what you should already know and explains a few things that you may not already know but should to get the most out of this book, such as tainting, security concerns, and troubleshooting.

Chapter 3, Using Your Environment. Many times in CGI applications you need information from the client, such as IP address or browser information. This chapter covers how to access the Web server environment variables and what they mean.

Chapter 4, Introduction to Web Forms. There are few online applications where there is not some sort of Web form used to allow an end user to submit information. Chapter 4 explains the HTML elements of creating a Web form, as well as how to obtain the user input.

Chapter 5, Working with Cookies. Using cookies to store data on a Web client can be very useful to record the preferences of and remember things about users. You will learn how to set, get, and use cookies in this chapter.

Chapter 6, Access Counters. Many people want to count how many people come to their Web site. The examples in this chapter show you how to do this.

Chapter 7, Web-Based File Uploading. Here you will learn how to safely allow end users to upload files to a server from their local hard drives.

Chapter 8, Tracking Clicks. It can sometimes be useful to know what links on a Web site are being followed and from where. The examples in this chapter show how to track these clicks.

Chapter 9, Using mod_perl. The popular mod_perl Apache module can be extremely useful when it is appropriate for an application. You will see how to configure mod_perl, as well as how to use and write mod_perl Perl modules.

Chapter 10, Web-Based E-mail. The examples in this chapter demonstrate how to connect to a POP3 server to view e-mail, view attachments, and send e-mail via the Web.

Chapter 11, Introduction to DBI and Databases on the Web. Chapters 1–10 presented basic uses for database connectivity in previous examples. This chapter examines the Perl DBI in more depth.

Chapter 12, Tied Variables. The magic of tying data structures to variables and how to do this when the data structure is a database is explained in this chapter.

Chapter 13, Embedding Perl in HTML with Mason. This popular tool is examined and explained. This chapter shows you how to embed Perl within HTML and use the HTML::Mason module to speed up development and maintenance time.

Chapter 14, Document Management via the Web. By now you will have learned how to upload files to a server. This chapter shows you how to manage your files remotely via the Web.

Chapter 15, Dynamically Manipulating Images. Creating charts, graphs, thumbnails, and galleries, and changing images on the fly are all concepts that can be useful in CGI applications. This chapter shows you how to add these techniques to your software.

Chapter 16, RSS and XML. XML is another tool that is gaining in use and popularity. This chapter shows you how to use both XML and a derivative of it, RSS and RDF, to share information and use in applications.

Appendix A, Server Codes. Learn what the codes returned by a Web server mean.

Appendix B, Environment Variables. This is a list of the most common Web server environment variables.

Appendix C, POSIX::strftime() Formats. This book uses the POSIX module a few times to format date strings. This list shows the formats that the module uses and what the formats do.

Appendix D, General Public License. If you didn't read the copy that came with Perl, you can do so here.

Appendix E, Artistic License. Another license under which Perl is distributed.

Appendix F, Perl Documentation. A list of the documentation that comes with Perl. This list is useful for interactive learning along with this book.

Appendix G, ASCII Codes. A list of ASCII, hex, and decimal codes.

Appendix H, Special HTML Characters. A list of special characters, such as £, ®, and Æ. Although these aren't specific to Perl, you will probably need some of them sooner or later when generating HTML with Perl.

Other Resources

One of the best resources for Perl is the Perl documentation and the documentation included in various Perl modules. Chapter 1 covers how to read this documentation with the perldoc command. The Perl homepage at http://www.perl.com is extremely useful with articles, tips, documentation, other resource links, and what's new in the world of Perl. The Perl Mongers homepage at http://www.perl.org supplies good information on the world of Perl and Perl advocacy. The use Perl Web site at http://use.perl.org is a community page where Perl information is shared and discussed. The Perl Documentation Web site at http://www.perldoc.com is a very useful site containing the latest Perl documentation. Finally, the Perl Monks at http://www.perlmonks.com is another community where people can ask questions, answer questions, chat, and share knowledge.

Usenet has Perl newsgroups that are also useful: comp.lang.perl.announce has Perl announcements; comp.lang.perl.misc is a high traffic list for asking Perl-related questions; and comp.lang.perl.modules announces and discusses Perl modules. A non-Perl-specific news group that deals with CGI is comp.infosystems.www.authoring.cgi. Here you can discuss all topics CGI.

Contacting Us

We would love to hear from you. You can find information on this book and errata at http://www.perlcgi-book.com and http://www.awl.com



0201710145P04062001

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020