Teach Yourself CGI Programming with PERL 5 in a Week, 2E

by Eric Herrmann


C  O  N  T  E  N  T  S



Introduction

Chapter 1   An Introduction to CGI and Its Environment

Chapter 2   Understanding How the Server and Browser Communicate

Chapter 3   Using Server Side Include Commands

Chapter 4   Using Forms to Gather and Send Data

Chapter 5   Decoding Data Sent to Your CGI Program

Chapter 6   Using Environment Variables in Your Programs

Chapter 7   Building an Online Catalog

Chapter 8   Using Existing CGI Libraries

Chapter 9   Using Imagemaps on Your Web Page

Chapter 10   Keeping Track of Your Web Page Visitors

Chapter 11   Using Internet Mail with Your Web Page

Chapter 12   Guarding Your Server Against Unwanted Guests

Chapter 13   Debugging CGI Programs

Chapter 14   Tips, Tricks, and Future Directions

Appendix A   MIME Types and File Extensions

Appendix B   HTML Forms

Appendix C   Status Codes and Reason Phrases

Appendix D   The ncSA imagemap.c Program

Appendix E   The Perl Quick Reference Manual

Credits


Copyright 1997 by Sams.net Publishing

SECOND EDITION

All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. For information, address Sams.net Publishing, 201 W. 103rd St., Indianapolis, IN 46290.

International Standard Book Number: 1-57521-196-3


HTML conversion by :
    M/s. LeafWriters (India) Pvt. Ltd.
    Website : http://leaf.stpn.soft.net
    e-mail : leafwriters@leaf.stpn.soft.net

Acknowledgments

It's not possible to write a book without a lot of help from all kinds of places:


About the Author

Eric Herrmann is the owner of Practical Internet, an online catalog and Web-page development company, and partner in Application Software Solutions Inc., a software development company focused on building intranets. Eric has a master's degree in Computer Science, 10 years of application programming experience in various asynchronous parallel processing environments, and is fluent in most of today's buzzwords: OOP, C++, UNIX, TCP/IP, Perl, and Java. Eric is happily settled on 10 acres of lovely Texas hill country in Dripping Springs, Texas, with his wife, Sherry, a riding instructor who speaks fluent horse; his three children, Scott, Jessica, and Steve; and 10 horses, 3 dogs, 4 cats, and 8 pet chickens :). When not playing at his computer, Eric helps with the horses, takes the kids fishing, or plays with model trains in the garage.


Tell Us What You Think!

As a reader, you are the most important critic and commentator of our books. We value your opinion and want to know what we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way. You can help us make strong books that meet your needs and give you the computer guidance you require.

Do you have access to CompuServe or the World Wide Web? Then check out our CompuServe forum by typing GO SAMS at any prompt. If you prefer the World Wide Web, check out our site at http://www.mcp.com.

Note
If you have a technical question about this book, call the technical support line at (800) 571-5840, ext. 3668.

As the team leader of the group that created this book, I welcome your comments. You can fax, e-mail, or write me directly to let me know what you did or didn't like about this book-as well as what we can do to make our books stronger. Here's the information:

Fax:317/581-4669
E-mail:newtech_mgr@sams.mcp.com
Mail:Mark Taber
Comments Department
Sams.net Publishing
201 W. 103rd Street
Indianapolis, IN 46290


Introduction

Teach Yourself CGI Programming with Perl 5 in a Week, 2E collects all the information you need to do Internet programming in one place.

In the first chapter, you will learn:

From there, you will learn about the basic client/server architecture of the server, and you will get a detailed description of the HTTP request/response headers. You will learn the client/server model in straightforward and simple terms, and throughout the book, you will learn about several methods for keeping track of the state of your client.

A full explanation of the unique environment of CGI programming is included in the chapters covering environment variables and server communications with the browser. The heart of CGI programming-understanding how data is managed between the client and the server-gets full coverage. Each step in data management-sending, receiving, and decoding data-is fully covered in its own chapter.

Each chapter of Teach Yourself CGI Programming with Perl 5 in a Week, 2E includes lots of programming and HTML examples. This book is an excellent resource for the novice Perl programmer; a detailed explanation of Perl is included with most programming examples. There is no assumption of the programming skills of the reader. Every programming example includes a detailed explanation of how the code works.

After teaching you the foundations of CGI programming, this book explores and explains the hottest topics of CGI programming. Make your Web page come alive with a clickable imagemap. Learn how to define the hotspots, where the existing tools are, and how to configure your server for imagemaps. Count the number of visitors to your Web page and learn about the pitfalls of getting their names. Learn how to create customizable mailing applications using the Internet sendmail format. And learn how to protect yourself from hackers, in a full chapter on Internet and CGI security.

You will find that this book is a great introduction and resource to the CGI programming environment on the Internet. Read on to begin understanding this fantastic programming environment, and good luck in all your programming endeavors. Have fun! It's more fun than not having fun.

What's New in This Edition

Teach Yourself CGI Programming with Perl 5 in a Week, 2E is a practical, hands-on guide to the world of CGI and Perl. This edition offers many new and revised examples and explanations. Furthermore, several readers suggested that more Perl foundation information would be helpful. The second edition includes new "Learning Perl" sections that focus exclusively on Perl concepts. This will give you, the reader, a much better understanding of both CGI and Perl as you work through each lesson in this book.

What This Book Is About

This book starts where most CGI tutorials leave off-just before you get into the really cool stuff! Fear not. If you are looking to take your Internet knowledge to the next level, you've made the right purchase. This book provides useful tips and hands-on examples for developing your own applications within the CGI programming environment using the Perl language. You get a complete understanding of the important CGI concepts, such as HTTP request/response headers, status codes, CGI/URI data encoding and decoding, and Server Side Include commands. You learn application development through examples in every chapter and with a complete application when you design an online catalog.

Specific features you'll see throughout the book follow:

Do                                        &nb sp;                                       Don't
Do/Don't boxes: These give you specific guidance on what to do and what to avoid doing when programming in the CGI environment and Perl.

Notes
These provide essential background information so that you not only learn to do things within the CGI environment and Perl, but also have a good understanding of what you're doing and why.

Tips
It would be nice to remember everything you've previously learned, but that's just about impossible. If there is important CGI or Perl material that you have to know, these tips will remind you.

Warnings
Here's where the author shares his insight and experience as a professional programmer-common bugs he has faced, time-saving coding techniques he has used, and pitfalls he has fallen into. Learn from his experiences.

What You Will Gain from This Book

Anyone who wants to know about programming on the Internet and in the CGI environment will benefit by reading this book. You spend several days covering advanced topics, yet a majority of this book is dedicated to helping you understand the CGI environment and Perl and then applying that knowledge to real applications. It is this hands-on approach to the CGI environment and the Perl language that sets this book apart from others. In addition to helping you develop an application, you learn the concepts involved in development.