![]()
CGI Programming 101
by Jacqueline D. HamiltonWelcome to CGI Programming 101. I started writing this class back in 1996, in an effort to help people learn CGI. CGI was, and often still is, thought of as some cryptic, difficult thing, but it's really not. It's easy to learn; if you know HTML, you can learn CGI. You don't need any prior programming experience; I'll show you everything you need to do, step by step. Since I launched this class, it's helped thousands of people learn the basics of CGI. (read some of their comments!) I hope it will help you, too.
This class is intended for anyone who knows HTML, but doesn't know Perl or CGI programming (and maybe doesn't know any programming at all). The goal here is to introduce you to writing Perl CGI scripts, teach you the basics of writing CGI's, and walk you through several examples of common CGI programming applications for the Web.
I've expanded this class into book form, as well - order your copy today!
The first six chapters available free here on this site. By working through them, you can learn how to write your own form-to-mail CGI's and flat-file databases. I strongly suggest working through these in order, because each chapter builds on material you learned in the previous chapter.
If you're ready to get started, click to the Introduction and let's begin!
Free Online Chapters
- Introduction - What is CGI? Why learn it? What do you need to get started?
- Chapter 1: Getting Started - where to write your scripts; how to upload to the Unix host; changing permissions; writing your first CGI
- Chapter 2: Perl Variables - Scalars, arrays, and hashes
- Chapter 3: CGI Environment Variables - Using data from environment variables; writing forms using GET
- Chapter 4: Processing Forms Writing forms using POST: a form-to-mail CGI
- Chapter 5: Advanced Forms Handling radio buttons, checkboxes, and select fields; writing a survey/poll CGI
- Chapter 6: Reading and Writing Data Files - File permissions; how to open, read, write, and close files
- Conclusion - where to go from here
The first six chapters are also available as a printable PDF file (57 pages, 160K).
You can also download the example scripts from the remaining chapters:
- Chapter 7: Multi-Script Forms - passing data between scripts; a flat-file catalog database and multi-part order form
- Chapter 8: Searching & Sorting
- Chapter 9: Using Server-Side Includes - SSI Syntax, list of SSI elemenets, how to include files and execute CGIs; SSI page counter; SSI error logger
- Chapter 10: Randomness - a random image picker; random password generator; random rotating ad banners
- Chapter 11: Redirects and Refreshes - how to send visitors to another page
- Chapter 12: Working With Strings - comparing, finding, joining, and formatting strings
- Chapter 13: Date and Time in Perl - how to generate the date; countdown/up clocks
- Chapter 14: Regular Expressions - pattern matching with Perl
- Chapter 15: HTTP Cookies - how to set and read cookies
- Chapter 16: Writing Secure Scripts - taint checking; protecting your data
- Chapter 17: Beyond Scripts: Perl Modules and CPAN - CGI.pm, GD.pm; where to find modules
- Chapter 18: Database Programming with Perl - an introduction to MySQL and DBI; an SQL-based catalog script; SQL page counter
- Chapter 19: Writing Your Own Modules
- Chapter 20: Working With Unix
- Appendix A: Online Resources
- Appendix B: Unix Tutorial and Command Reference
- Appendix C: Password Tutorial (updated into a complete new chapter - click here to access it!)
This book and class is written by Jacqueline Hamilton. Copyright © 1999, 2000 by Jacqueline Hamilton; all rights reserved.
Source Code / Examples From The Book
All of the source code from the book is available online, along with links to resources and FAQs from each chapter. Click here to access the chapter listing.
Comments
To post comments about the book or class, visit the comments page. If you have CGI-related questions, check out our discussion boards. If you need website design or custom CGI programming, try one of our freelancers.
Frequently Asked Questions
Actually I like to think that I've answered the most frequently asked questions in the book itself... but here I've dealt with some specific questions that haven't been covered in the book or class.
Class Bookshelf
Here are a number of books that may be useful to you if you're taking this class, or if you're just looking for a good CGI reference.
Tell A Friend!