In 1996, CGI was the only stable and well-understood method forcreating dynamic content on the Web. However, very few sitesexploited its full potential. In the first edition, Shishir wrote:
Todays computer users expect custom answers to particularquestions. Gone are the days when people were satisfied by thecomputing center staff passing out a single, general report to allusers. Instead, each salesperson, manager, and engineer wants toenter specific queries and get up-to-date responses. And if a singlecomputer can do that, why not the Web?
This is the promise of CGI. You can display sales figures forparticular products month by month, as requested by your staff, usingbeautiful pie charts or plots. You can let customers enter keywordsin order to find information on your products.
In 1996, these were bold claims. Today, they describe business asusual. That promise of CGI has certainly been fulfilled.
This book is about more than writing CGI scripts. It is aboutprogramming for the Web. Although we focus on CGI programming withPerl (thus the title change for this edition), many of the conceptswe cover are common to all server-side web development. Even if youfind yourself working with alternative technologies down the road,the effort you invest learning CGI now will continue to yield valuelater.
Whats in the Book
Because CGI has changed so much in the last few years, it is onlyappropriate that this new edition reflect the changes. Thus, most ofthis book has been rewritten. New topics include CGI.pm, HTMLtemplates, security, JavaScript, XML, search engines, stylesuggestions, and compatible, high-performance alternatives to CGI.Previous topics, such as session management, email, dynamic images,and relational databases, have been expanded and updated. Finally, wemodified our presentation of CGI to begin with a discussion of HTTP,the underlying language of the Web. An understanding of HTTP providesa foundation for a more thorough understanding of CGI.
Despite the changes, the original goal of this book remains the same:to teach you everything you need to know to become a good CGIdeveloper. This is not a learn-by-example bookit isntbuilt around a handful of CGI scripts with a discussion of how eachscript works. There are already lots of books like that available forCGI. While these books can certainly be useful, especially if one ofthe examples matches a particular challenge you are facing, theyoften teach how without explaining why . The aim of this book is to cover thefundamentals so that you can create CGI scripts to tackle anychallenge. Dont worry, though, because well look atlots of examples. But our examples will serve to illustrate thediscussion, rather than the other way around.
We should admit up front that there is a Unix bias in this book. BothPerl and CGI were originally conceived for the Unix platform, so itremains the most popular platform for Perl and CGI development. Ofcourse, Perl and CGI support numerous other systems, includingMicrosofts popular 32-bit Windows systems: Windows 95, Windows98, Windows NT, and Windows 2000 (hereafter collectively referred toas Win32 ). Throughout this book, we willfocus on Unix, but well also point out those things you needto be aware of when developing for non-Unix-compatible systems.
We use the Apache web server throughout our examples. There areseveral reasons: it is the most popular web server used today, it isavailable for the most platforms, it is free, it is open source, andit supports modules (such as mod_perl and mod_ fastcgi ) that improve both the power andthe performance of Perl for web development.
What You Are Expected to Know Before Reading
You should already be comfortable with Perl. Although the firstedition of CGI Programming on the World WideWeb discussed other programming languages, this editionof CGI Programming with Perl (as the new nameimplies) focuses exclusively on Perl. CGI supports a wide variety ofprogramming languages, but Perl has certainly become the language ofchoice.
If you do not already know Perl, an excellent introductionis Learning Perl, Second Edition, by RandalSchwartz and Tom Christiansen (published by OReilly &Associates, Inc.). Once you understand the basics, we stronglyrecommend you get a copy of Programming Perl, ThirdEdition (affectionately known as The CamelBook) by Larry Wall, Tom Christiansen, and Jon Orwant(OReilly & Associates, Inc.). It is the standard referenceused by Perl developers everywhere. Additional Perl resources arelisted in .
We will discuss many modules from CPAN, theComprehensive Perl Archive Network. If youhave not downloaded and installed modules from CPAN before, refer to.
You should also be familiar with perldoc, thestandard tool for browsing Perl documentation.perldoc is useful for two reasons. First, itallows you to access the convenient and extensive documentationdistributed with Perl. Second, it is essential for learning to usemodules downloaded from CPAN. perldoc is alsopresented in .
Overview of the Book
presents a general introduction to CGI,including history, web server configuration, and a sample CGI script.
cover the basics of using CGI. We begin withan overview of HTTP and then see how CGI builds upon it. We then lookat HTML forms, which are a common way to pass information to CGIscripts.
look at several popular modules available tohelp us write CGI scripts easily. We also compare differentstrategies for generating dynamic HTML output.
looks at how a different technology,JavaScript, can be used with CGI scripts to create more powerfulsolutions.
present solutions to challenges and tasks thatCGI scripts commonly face. These chapters include general topics suchas online security, storing permanent data, and tracking users acrosspages, as well as more specific topics such as sending email,allowing users to search your site, and creating dynamic images.
covers middleware and XML, which enableyour CGI scripts to provide an interface with other informationservers.