The two links below will take you into the online edition of CGI Manual of Style and download a zip file that contains all the code mentioned within the book.
| Acquisitions Editor | Suzanne Anthony |
| Coordinating Editor | Kelly Green |
| Editor | Deborah Craig |
| Technical Reviewer | Jason Wehling |
| Project Coordinator | Ami Knox |
| Cover Illustration and Design | Megan Gandt |
| Book Design | Gary Suen |
| Word Processing | Howard Blechman |
| Page Layout | Janet Piercy |
| Indexer | Julie Kawabata |
Ziff-Davis Press, ZD Press and the Ziff-Davis Press logo are trademarks or registered trademarks of, and are licensed to Macmillan Computer Publishing USA by Ziff-Davis Publishing Company, New York, New York.
Ziff-Davis Press imprint books are produced on a Macintosh computer system with the following applications: FrameMaker®, Microsoft® Word, QuarkXPress®, Adobe Illustrator®, Adobe Photoshop®, Adobe StreamlineTM, MacLink®Plus, Aldus® FreeHandTM, Collage PlusTM.
Ziff-Davis Press, an imprint of Macmillan Computer Publishing USA 5903 Christie Avenue Emeryville, CA 94608
Copyright © 1996 by Macmillan Computer Publishing USA. All rights reserved. PART OF A CONTINUING SERIES
All other product names and services identified throughout this book are trademarks or registered trademarks of their respective companies. They are used throughout this book in editorial fashion only and for the benefit of such companies. No such uses, or the use of any trade name, is intended to convey endorsement or other affiliation with the book.
No part of this publication may be reproduced in any form, or stored in a database or retrieval system, or transmitted or distributed in any form by any means, electronic, mechanical photocopying, recording, or otherwise, without the prior written permission of Macmillan Computer Publishing USA, except as permitted by the Copyright Act of 1976, and except that program listings may be entered, stored, and executed in a computer system.
THE INFORMATION AND MATERIAL CONTAINED IN THIS BOOK ARE PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY WARRANTY CONCERNING THE ACCURACY, ADEQUACY, OR COMPLETENESS OF SUCH INFORMATION OR MATERIAL OR THE RESULTS TO BE OBTAINED FROM USING SUCH INFORMATION OR MATERIAL. NEITHER MACMILLAN COMPUTER PUBLISHING USA NOR THE AUTHOR SHALL BE RESPONSIBLE FOR ANY CLAIMS ATTRIBUTABLE TO ERRORS, OMISSIONS, OR OTHER INACCURACIES IN THE INFORMATION OR MATERIAL CONTAINED IN THIS BOOK, AND IN NO EVENT SHALL MACMILLAN COMPUTER PUBLISHING USA OR THE AUTHOR BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF SUCH INFORMATION OR MATERIAL.
ISBN 1-56276-397-0
Manufactured in the United States of America
First and foremost, I want to thank my wife, Vonda, for bearing with me during the past few months. She accepted the reduction in our time together as well as taking on some of the tasks that I no longer had time for. She also continually inspired me when my own motivation waned. She always brings out the best in me.
I also want to thank Suzanne Anthony, Kelly Green, and Deborah Craig for guiding me through this project and introducing me to the world of computer book publishing. All three of you have given me advice in areas where my technical knowledge was of no help.
Finally, I am eternally indebted to those men and women who pass on their knowledge about the Internet through Web pages, online documentation, newsgroup postings, and mailing list e-mails. It was the knowledge I gained from these resources that made this book possible.
Over the past few years, the Internet has emerged from relative obscurity and become a household name. Most of this growth can be attributed to the World Wide Web, which is just one area of the Internet. Before the Web evolved, the Internet was primarily a text-based environment, not known for being particularly accessible. Most people were not interested by this type of text-based setting--many even found it intimidating. What the World Wide Web offered, which the rest of the services on the Internet had not, was a rich multimedia experience. Web pages could incorporate images, sounds, and video, giving Web sites vast audience appeal. The World Wide Web transformed the Internet from a tool for experts and specialists into a user-friendly, exciting, and entertaining environment in which you could get work done or have fun, all with a few mouse clicks or keystrokes.
You are probably already somewhat familiar with the World Wide Web. You most likely have even heard of CGI scripts and are looking for information about how to write your own. But what made you pick up this book? Did you choose it because it's smaller than the others on the shelf? Did you think it would be concise and would present you with exactly the information you need to get started? If so, you won't be disappointed. This book is a brief but thorough introduction to CGI scripting. It can be both simply because you do not need to learn a lot to write CGI scripts.
This book is organized so you can quickly learn what you need to know and get started with your own CGI scripts. It is divided into three parts, each with a specific focus. You don't need to read this book from cover to cover to start writing your own CGI scripts. You only need to read the sections that supply the information you need or that include examples of interest to you.
The first part, which contains three chapters, is an introduction to the nuts and bolts of CGI scripting. The first chapter presents an overview of the Internet, the World Wide Web, HTML, and CGI. It introduces concepts that are important to CGI, such as URLs, HTTP, and the division between client and server computers. If you already have a good grasp of this material and of what CGI is in general, go ahead and skip to Chapters 2 and 3, which supply you with all of the tools you need to begin writing your own scripts. Chapter 2 explains how your script gets data from the Web server and sends output back to the Web browser. Chapter 3 addresses CGI programming issues, such as choosing a programming language, where to place your script files, how to call your scripts from the Web browser, common errors, and security.
The second part of the book includes six chapters that present six practical examples of CGI scripts. These examples reflect some of the most common applications of CGI scripts on the Web. You'll find example form handlers, guest books, shopping carts, access counters, and bulletin boards. There are also some simple examples that demonstrate how to interact with databases and how to animate your Web pages.
At the end of the book is a Quick Reference that lists a number of online resources This section contains a collection of Web URLs, newsgroups, and mailing lists where you can go to for further information on CGI, HTML, HTTP, the World Wide Web, and the Internet. Don't hesitate to explore; that's what using the Web is all about. That's also how you'll find the most up-to-date information available.
Most of the scripts in this book are written in Perl version 5, with one example in C, but no prior knowledge of Perl or C is assumed. The functionality of each code segment is explained thoroughly, allowing you to rewrite the code in your language of choice. However, if your project does not restrict you to a certain language, I highly recommend becoming acquainted with Perl. If you already know any programming language, Perl is easy to learn; it is also very well suited for CGI scripting. If you need help learning Perl, check the resources listed in the Perl section of the Quick Reference at the end of the book.
All of the scripts in this book have been tested on three machines. The first is a DEC Alpha 1000 running the OSF version 3.2 version of UNIX. Because the examples are written in Perl, they contain no machine-specific code and should work equally well under any other UNIX configuration. The DEC Alpha was running Netscape's Communications Server version 1.1 as the Web server. The scripts have also been tested on both a Windows 95 and Windows NT (version 3.51) machine. The Windows 95 machine is a Compaq Deskpro 5120 (120 MHz Pentium machine) with 48MB of RAM. The Windows NT machine is a Gateway 2000 433V (33 MHz 486 machine) with 20MB of RAM. Both Windows machines were using O'Reilly's WebSite version 1.1 as the Web server.
The Internet is in a constant state of flux. Because of this, I highly recommend that you investigate the online resources listed in the Quick Reference for further information after reading this book. I also welcome any comments or questions you may have regarding the content of this book or the Internet in general. You can reach me at robertm@deltanet.com. In the meantime, welcome to CGI scripting!