Writing Cgi Applications With Perl

by ;
Edition: 1st
Format: Paperback
Pub. Date: 2001-02-15
Publisher(s): Addison-Wesley Professional
List Price: $48.62

Rent Book

Select for Price
There was a problem. Please try again later.

New Book

We're Sorry
Sold Out

Used Book

We're Sorry
Sold Out

eBook

We're Sorry
Not Available

How Marketplace Works:

  • This item is offered by an independent seller and not shipped from our warehouse
  • Item details like edition and cover design may differ from our description; see seller's comments before ordering.
  • Sellers much confirm and ship within two business days; otherwise, the order will be cancelled and refunded.
  • Marketplace purchases cannot be returned to eCampus.com. Contact the seller directly for inquiries; if no response within two days, contact customer service.
  • Additional shipping costs apply to Marketplace purchases. Review shipping costs at checkout.

Summary

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 <

Author Biography

Kevin Meltzer has been using Perl since the early '90s for everything from CGI and system administration to database migrations and report generation. He considers himself a "Perl evangelist," and is the founder of the Hartford Perl Mongers (although he now resides in Florida). Kevin has been published in The Perl Journal, and is the judge of their annual Perl Poetry Contest. He is now working for Verio, Inc. as a Perl developer/engineer.

Brent Michalski discovered Perl around 1994 and has been programming in it ever since. He considers himself a "Perl freak" and loves sharing Perl with others. Brent mainly develops CGI applications because he enjoys the Web so much. He has written articles for Web Review, and currently maintains the Perl area on the Dr. Dobb's Journal Web site. Brent is a senior developer at MasterCard International where they let him play with Perl every day.



0201710145AB04062001

Table of Contents

Foreword xiii
Preface xv
Acknowledgments xix
Perl, CGI, and this Book
1(14)
What is Perl?
1(2)
What is CGI?
3(2)
Why Perl is Good for CGI
4(1)
About this Book
5(5)
Who is this Book For?
6(1)
Conventions Used in this Book
6(1)
Using perldoc
7(3)
Using the CPAN
10(5)
What You Should Know
15(30)
Prerequisites
15(3)
Editors
18(1)
File Permissions
18(1)
Basic Security Concerns
19(1)
Using-T
20(2)
Checking for Taintedness and Laundering Data
22(5)
Your PATH and -T
27(2)
Installing a Script
29(3)
Troubleshooting
32(6)
Caching
38(4)
The Expires HTTP Header
40(1)
Cache-Control HTTP Header
41(1)
Listings
42(3)
Using Your Environment
45(24)
Introduction to %ENV
45(3)
Adding to %ENV
48(5)
Form Input Primer
53(2)
Example Script: Visitor Log
55(7)
Example Script: Basic Report
62(3)
Reader Exercise
65(1)
What Have We Learned?
66(1)
Listings
67(2)
Introduction to Web Forms
69(36)
Introduction
69(5)
Form Tags
74(10)
Reading Form Input with CGI.pm
84(8)
Making Your Users Happy
92(1)
Final Example
93(7)
User Exercises
100(1)
Program Listings
101(4)
Working with Cookies
105(18)
Introduction
105(1)
Security
106(1)
Limitations
106(1)
Cookie Pieces
106(2)
Working with Cookies the Manual Way
108(3)
Baking Cookies with CGI.pm
111(3)
Controlling User Preferences with Cookies
114(7)
User Exercises
121(2)
Access Counters
123(20)
Introduction
123(1)
Example Script: SSI Text Counter
124(6)
Example Script: SSI Image Counter
130(3)
Example Script: SSI Text Counter, with a Twist
133(3)
Example Script: An Imageless Image Counter
136(3)
Counter Conclusion
139(1)
Reader Exercises
140(1)
Listings
140(3)
Web-Based File Uploading
143(38)
Introduction
143(1)
File Uploading Basics
144(16)
Viewing Files
160(3)
Uploading Multiple Files
163(9)
Reader Exercises
172(1)
File Listings
173(8)
Tracking Clicks
181(16)
Introduction
181(1)
Example Script: A Simple Click Tracker
182(5)
Example Script: Random Images
187(5)
Example Script: Click Tracking (Reprise)
192(1)
Reader Exercises
193(1)
Listings
194(3)
Using mod_perl
197(32)
What is mod_perl?
197(2)
Configuring mod_perl
199(2)
Apache::Registry
201(3)
Automatic Headers and Footers with Apache::Sandwich
204(5)
A mod_perl Photo Album with Apache::Album
209(8)
Authentication with Apache::AuthDBI
217(3)
Writing a mod_perl Handler
220(6)
Reader Exercises
226(1)
Listings
226(3)
Web-Based E-mail
229(38)
Introduction
229(1)
Example Script: Checking POP3 Mail via the Web
230(14)
Example Script: Reading E-mail via the Web
244(9)
Example Script: Displaying Attachments
253(3)
Example Script: Composing E-mail
256(4)
Reader Exercises
260(1)
Listings
261(6)
Introduction to DBI and Databases on the Web
267(26)
Introduction
267(2)
Using the Perl DBI
269(1)
Connecting to the Database
270(2)
Disconnecting from the Database
271(1)
Preparing and Executing an SQL Query
272(2)
Fetching Data
274(7)
The fetchall_arrayref( ) Method
274(3)
The fetchrow_arrayref( ) Method
277(2)
The fetchrow_hashref( ) Method
279(1)
The blind_columns( ) Method
280(1)
Putting It All Together
281(6)
The do( ) Method
286(1)
Wrapping It Up
286(1)
Reader Exercises
287(1)
Listings
287(6)
Tied Variables
293(46)
Introduction
293(2)
Setting It All Up
295(1)
Getting Started
296(1)
Diving In
297(10)
The Main Program
307(9)
Finishing the ShopCart Module
316(10)
Running the Program
326(3)
Wrapping It Up
329(1)
Program Listings
330(9)
Embedding Perl in HTML with Mason
339(30)
Introduction
339(1)
Installation
340(1)
The Strategy
340(1)
Mason Syntax
340(4)
Special Mason Components
344(1)
Cascading Execution
344(1)
Moving Right Along
345(5)
rss2html
350(6)
my_news
356(1)
footer
357(3)
Wrapping it Up: The Code for the Example Site
360(9)
Document Management via the Web
369(50)
Introduction
369(1)
The Plan
370(2)
auth.cgi
372(6)
shared.pl
378(3)
main.cgi
381(9)
upload.cgi
390(11)
viewer.cgi
401(5)
Program Listings
406(13)
Dynamically Manipulating Images
419(30)
Introduction
419(1)
Adding Shapes and Text
420(4)
Creating a Dynamic Graph
424(8)
Creating Thumbnail Images
432(4)
Filtering Images with Image::Magick
436(6)
Animated Images
442(1)
Reader Exercises
443(1)
Listings
444(5)
RSS and XML
449(22)
XML and RSS Overview
449(1)
Structure of an XML Document
450(1)
News Portals with RSS
450(14)
A Home Page News Portal
453(11)
Creating an RSS File
464(2)
Reader Exercises
466(1)
Listings
466(5)
Appendix A Server Codes 471(4)
100-199: Provide confirmation that a request is being processed
471(1)
200-299: Request was performed
471(1)
300-399: Request not performed
472(1)
400-499: Request is incomplete
472(2)
500-599: Internal server errors
474(1)
Appendix B Environment Variables 475(2)
Appendix C POSIX::strftime( ) Formats 477(4)
Appendix D General Public License 481(8)
Appendix E Artistic License 489(4)
Appendix F Perl Documentation 493(4)
Appendix G ASCII Codes 497(6)
Appendix H Special HTML Characters 503(6)
Resources 509(2)
Index 511

Excerpts

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.

An electronic version of this book is available through VitalSource.

This book is viewable on PC, Mac, iPhone, iPad, iPod Touch, and most smartphones.

By purchasing, you will be able to view this book online, as well as download it, for the chosen number of days.

Digital License

You are licensing a digital product for a set duration. Durations are set forth in the product description, with "Lifetime" typically meaning five (5) years of online access and permanent download to a supported device. All licenses are non-transferable.

More details can be found here.

A downloadable version of this book is available through the eCampus Reader or compatible Adobe readers.

Applications are available on iOS, Android, PC, Mac, and Windows Mobile platforms.

Please view the compatibility matrix prior to purchase.