This book is intended for web designers, entrepreneurs, students, teachers,
and anyone who is interested in learning CGI programming.
A D V E R T I S E M E N T
You do not need any
programming experience to get started; if you can write HTML, you can write CGI
programs. If you have a website, and want to add guestbook forms, counters,
shopping carts, or other interactive elements to your site, then this book is
What is CGI?
"CGI" stands for "Common Gateway Interface." CGI is one method by which a web
server can obtain data from (or send data to) databases, documents, and other
programs, and present that data to viewers via the web. More simply, a CGI is a
program intended to be run on the web. A CGI program can be written in any
programming language, but Perl is one of the most popular, and for this book,
Perl is the language we'll be using.
Why learn CGI?
If you're going to create web pages, then at some point you'll want to add a
counter, a form to let visitors send you mail or place an order, or something
similar. CGI enables you to do that and much more. From mail-forms and counter
programs, to the most complex database programs that generate entire websites
on-the-fly, CGI programs deliver a broad spectrum of content on the web today.
Why use this book?
This book will get you up and running in as little as a day, teaching you the
basics of CGI programs, the fundamentals of Perl, and the basics of processing
forms and writing simple programs. Then we'll move on to advanced topics, such
as reading and writing data files, searching for data in files, writing
advanced, multi-part forms like order forms and shopping carts, using randomness
to spice up your pages, using server-side includes, cookies, and other useful
CGI tricks. Things that you've probably thought beyond your reach, things you
thought you had to pay a programmer to do . . . all of these are things you can
easily write yourself, and this book will show you how.
You can also try it out before buying the book; the first six chapters are
available online, free of charge, at http://www.cgi101.com/book/.
What do you need to get started?
You should already have some experience building web pages and writing HTML.
You'll also need Perl and a web server (such as Apache) that is configured to
allow you to run your own CGI programs.
The book is written towards CGI programming on Unix, but you can also set up
Apache and Perl on Mac OS X and Windows. I've written several online tutorials
that will show you how to get started:
- Windows XP:
how to set up Apache and Perl; how to configure Apache; where to write your
programs; differences between CGI programs on XP and Unix
- Mac OS X:
how to configure Apache (which you already have installed); where to write
How to upload programs to your Unix-based ISP;
Unix tutorial; where
to write your programs; Unix permissions.
Conventions Used in this Book
Perl code will be set apart from the text by indenting and use of a
Unix shell commands are shown in a bold font: chmod 755 filename
What's New In This Edition?
The 2nd edition of CGI Programming 101 has been substantially revised
from the first edition. You'll learn about Perl modules from the beginning, and
work with modules (including the CGI.pm module, which offers many great features
for writing CGI programs) throughout the book. You'll learn how to password
protect an area on your website, how to build an online catalog with a shopping
cart, how to work with cookies, how to protect your site from spammers, and much