CGI Programming 101: Learn CGI Today!
If you want to add guestbooks, page counters, shopping carts and other interactive elements to your website, you can either pay for expensive software to do it for you, or you can learn how to write your own. This class will show you how. CGI programming (that is, programming for the web) is easy to learn; if you know HTML, you can learn CGI. You don't need any prior programming experience.Self-Paced Learning
The first six chapters of CGI Programming 101 are available free here on this site. By working through them, you'll learn how to write your own form-to-mail program, and how to read and write to data files. You should work through these in order, because each chapter builds on material you learned in the previous chapter.What You Need
You'll need Perl and a web server (like Apache). The book is written towards Unix, but you can easily set up Apache and Perl on Mac and Windows. I've written several tutorials of how to get started; choose the one that's right for you:
- 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 your programs
- Unix: How to upload programs to your Unix-based ISP; Unix tutorial; where to write your programs; Unix permissions.
If you need an ISP that offers CGI hosting, visit CGI101. We offer Unix shell access, CGI programming, a MySQL database, and all of the Perl modules used in the class and book. It's an easy, hassle-free way to get started writing your own programs.
Once you've gotten your server set up and you're ready to start writing CGI programs, go to the Introduction.
The following material is from the newly updated 2nd edition of CGI Programming 101 (now shipping!)
If you're looking for source code from the first edition, click here.
Chapters 1-6: Full Text Online
When you're ready to go beyond the online class, order the book and learn about databases, Perl modules, file uploading and more.
- Introduction - What is CGI? Why learn it? What do you need to get started?
- Chapter 1: Getting Started [text] [programs] - where to write your programs; how to upload to the Unix host; changing permissions; writing your first CGI
- Chapter 2: Perl Variables [text] [programs] - Scalars, arrays, and hashes
- Chapter 3: CGI Environment Variables [text] [programs] - Using data from environment variables; writing forms using GET
- Chapter 4: Processing Forms and Sending Mail [text] [programs] - Writing forms using POST: a form-to-mail CGI
- Chapter 5: Advanced Forms and Perl Control Structures [text] [programs] - Handling radio buttons, checkboxes, and select fields; writing a survey/poll CGI
- Chapter 6: Reading and Writing Data Files [text] [programs] - File permissions; how to open, read, write, and close files
The first six chapters are also available as a printable PDF file (78 pages, 609K).
Source Code from Remaining Chapters:
- Chapter 7: Working With Strings - comparing, finding, joining, and formatting strings
- Chapter 8: Server-Side Includes - SSI Syntax, list of SSI elements, how to include files and execute CGI programs; SSI page counter; SSI error logger
- Chapter 9: Working With Numbers - number operators and functions; random numbers; a random image picker; random rotating ad banners
- Chapter 10: Redirection
- Chapter 11: Multi-Script Forms - a web catalog and order form
- Chapter 12: Searching & Sorting
- Chapter 13: Regular Expressions - pattern matching with Perl
- Chapter 14: Perl Modules
- Chapter 15: Date and Time in Perl - how to generate the date; modules for formatting the date; countdown/up clocks
- Chapter 16: Database Programming with Perl - an introduction to MySQL and DBI; SQL catalog; SQL page counter
- Chapter 17: HTTP Cookies - how to set and read cookies
- Chapter 18: Writing Your Own Modues
- Chapter 19: CGI Security - taint checking; protecting your data
- Chapter 20: Password Protection
- Appendix A: Unix Tutorial and Command Reference
This book and class is written by Jacqueline Hamilton. Copyright © 2004, 1999 by Jacqueline Hamilton; all rights reserved. No part of this material may be reposted on another website.
Comments
To post comments about the book or class, visit the comments page. If you have CGI-related questions, check out our discussion boards.
To send feedback about the book or this site, use the secure mail form.
Bookshelf
Here are a number of books that may be useful to you as you're learning CGI.