CGI Programming Unleashed
CGI Programming Unleashed
by Eugene Eric Kim
C O N T E N T S
Chapter 1 What CGI Programs Can and Can't Do
Chapter 2 The CGI Specification
Chapter 3 Crash Course in CGI
- Why CGI Exists
- Wanna Have a Conversation?
- Parlez Vous Environment Variables?
- Taking It All In
- RSVP
- Some Things to Consider
- Summary
Chapter 4 Comparison of the Various CGI Programming Libraries
Chapter 5 Designing Your CGI Application
Chapter 6 Testing and Debugging
- The Process and Methodology
- Solitary Confinement
- Ladies and Gentlemen, Start Your Testing
- Debugging the Application
- Summary
Chapter 7 Server-Side Includes (SSI) and Gateway
- What Are Server-Side Includes, and What Are They Useful For?
- Comparison of SSI and CGIs
- Which Servers Support SSI?
- A List of Useful SSI Directives
- Some SSI Examples
- The Protocol of the Web: HTTP
- Gateways: Accessing Other Protocols through the Web
- Improving Existing Gateways
- Some Gateway Examples
- Using the Web as a Standard Internet Access Interface
- Summary
Chapter 8 Forms and How to Handle Them
Chapter 9 Security
Chapter 10 Databases
Chapter 11 Searching and CGI
- Searching Information on the Web
- Most Important Search Engines
- Gathering Information on the Internet
- Searching Interfaces for the Final User
- CGI Work in the Background
- Developing a Simple CGI for a White Pages Database
- Future Improvements
- Summary
Chapter 12 Imagemaps
- Imagemaps-Myth, Metaphor, and Meaning
- Anatomy of an Image-Pixels and Coordinates
- HTML, ISMAP, and QUERY_STRING- Passing Imagemap Information to a CGI Program
- Flatland Revisited-An Introduction to the Standard Imagemap System
- Client-Side Imagemaps and Magic MIME Types
- Take a Walk on the Server-Side-Developing Imagemap Code
- Creative Imagemap Programming-Breaking the Paradigm with Glorglox
- Imagebuttons-The End of Imagemaps Is Nigh
- Summary
Chapter 13 Proprietary Extensions to Servers
Chapter 14 WinCGI The Basics
Chapter 15 Windows CGI: Database Backending
- Database and Data Formats
- Communicating with Databases
- Database Tools
- Creating Your Database
- Summary
Chapter 16 DOS CGI: The Basics
Chapter 17 Voting Booths
- Voting Booths-Gathering and Managing Opinions
- Starting Simple-A Low-Level Voting Booth
- Bad Voting Booth, Good Code-Technical Merits of greenegg.cgi
- Use of Associative Arrays for the Handling of GET/POST Method Data
- Immediate Error Trapping Using the Statement Modifier Form of if
- Slurping Data with @array = <FILEHANDLE>;
- Use of Output Filter to Provide stdin to /usr/sbin/sendmail and sendmail -t Flag
- Use of print FH<<END; ... END Syntax When Outputting Formatted Sections
- A Voting Booth Wish List
- Multistate CGI Programs-More Than Just a URL
- Generating Meaningful Reports
- Summary
Chapter 18 Discussion Forums
- Discussion Forums-Everything Old Is New Again
- Discussion Forum Display and Bistate CGI Programming
- Useful Data Fields for Discussion Forums and Parent/Sibling/Child Relationships
- A Discussion Forum Example
- Discussion Forum Administration
- Discussion Forum Additions
- Selective Sorting Criteria
- Search Engines
- Registered Users and .htaccess Schemes
- Summary
Chapter 19 Chat Rooms
- Chat Rooms-Getting a Life on the Internet
- Prescription for a Chat Room
- Getting chat.cgi to Work for You
- Chat Room Systems and Entry Pages
- Extension to the Basic Chat Room
- Intelligent User Identification
- ChatMaster-The Chat Room Administrator
- Private Messaging
- Alternatives to CGI Chat Rooms
- Summary
Chapter 20 Multi-User Games and CGI
Chapter 21 Tracking Users
- Why Do We Need to Track Users?
- The Essence of Web Marketing
- Parsing Access Logs
- Environment Variables
- Creating a Pseudo Access Log File
- Logging Accesses
- How to Implement Tracking CGIs
- A Simple Web Counter
- Calling counter.cgi
- Locating Users Geographically
- Cookies
- Other Methods of Tracking Users
- The Ethics of Tracking Users
- Accessing This Chapter Online
- Summary
Chapter 22 Simple Order Entry
- Forms and the Data They Produce
- Processing the Data with Perl
- Checking for Errors
- Security Issues
- Summary
Chapter 23 Shopping Carts
- What Are Shopping Cart CGIs?
- What This Chapter Covers
- The Basic Elements of a Shopping Cart CGI
- Other Ways of Keeping Track of State
- Database Management
- The Result of Your Labors, cart.cgi
- Summary
Chapter 24 Java and JavaScript Alternatives to CGI
- Java: Bringing More Dynamics to the Web
- What Is JavaScript?
- Differences between Java and JavaScript
- Comparison of CGI and Java/JavaScript
- Communication between Java and CGI
- Java to CGI
- CGI to Java
- Java and JavaScript
- JavaScript
- Each Technique Has Its Place
- Future Improvements
- Where to Get More Information
- Summary
Chapter 25 ISAPI
Chapter 26 NSAPI
- Why NSAPI?
- NSAPI versus CGI
- NSAPI and the Server's Processes
- Functions and Features
- Implementation Considerations
- The Future of the NSAPI
- Summary
Chapter 27 ActiveXControls
- ActiveX Concepts and Background
- Why They Matter
- ActiveX Controls in Action
- Developing ActiveX Controls
- Integrating Controls with Your Web Site
- ActiveX Viability and Directions
- Resources
- Summary
Chapter 28 ActiveX Scripting
- Blending HTML and Programming
- The ActiveX Scripting Model
- The Languages
- Scripting Hosts and Engines
- Resources
appendix A Web Resources
Copyright C 1996 by Sams.net Publishing
FIRST 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-151-3
HTML conversion by :
M/s. LeafWriters (India) Pvt. Ltd.
Website : http://leaf.stpn.soft.net
e-mail :
leafwriters@leaf.stpn.soft.net
All terms mentioned in this book that are known to be trademarks
or service marks have been appropriately capitalized. Sams.net
Publishing cannot attest to the accuracy of this information.
Use of a term in this book should not be regarded as affecting
the validity of any trademark or service mark.
President, Sams Publishing | Richard K. Swadley |
Publishing Team Leader | Greg Wiegand |
Managing Editor | Cindy Morrow |
Director of Marketing | John Pierce |
Assistant Marketing Managers | Kristina Perry, Rachel Wolfe |
Acquisitions Editor | Christopher Denny | Development Editors | Anthony Amico, Keith, Davenport, Jeff Koch |
Software Development Specialist | Brad Meyers | Production Editor | Anne Owen |
Copy Editors | Brice Gosnell, Chuck Hutchinson, Kris Simmons | Indexer | John Hulse |
Technical Reviewers | Ian Anderson, Raj Mangal, Patrick McKeown, Christopher Stone, Matthew Stone | Editorial Coordinator | Katie Wise |
Technical Edit Coordinator | Lynette Quinn | Resource Coordinator | Deborah Frisby |
Editorial Assistants | Carol Ackerman, Andi Richter, Rhonda Tinch-Mize | Cover Designer | Tim Amrhein |
Book Designer | Gary Adair | Copy Writer | Peter Fuller |
Production Team Supervisor | Brad Chinn | ||
Production | Stephen Adams, Debra Bolhuis, Mona Brown, Kevin Cliburn, Michael Dietsch, Jason Hand, Daniel Harris, Chris Livengood, Casey Price, Laura Robbins, Bobbi Satterfield, Becky Stutzman, Susan Van Ness |
About the Authors
Daniel Berlin is a high-school senior at The Peddie School in New Jersey. He has worked as a programmer in local industry during summer vacations, and he has done technical editing and consulting in the past year. He expects to pursue a career in computer science and law. Dan is well known in the CompuServe community, where he has been a forum leader of various forums as well as an active contributor.
Richard Liam Dice is the vice president of Anadas Software and Internet Development, a Canadian company specializing in the production of high-end Web sites and CGI programming. He studied at the University of Western Ontario and has a B.Sc. degree in applied mathematics, concentrating on programming mathematical models of physical and astrophysical situations. His first exposure to the Internet was in 1990. He has been a regular user of the Internet and a UNIX programmer since 1992. Richard started using the Web in mid-1993 and has been programming CGI applications, usually using Perl 4, since early 1995.
António Miguel Ferreira is one of the founders and the Web expert of Esoterica S.A., an Internet service provider in Portugal. He graduated with a degree in computer science and engineering in INSA Lyon, France. He has developed financial-analysis software and currently manages several corporate Web sites for different kinds of clients, based on different hardware and software platforms. He has authored technical articles in some magazines. His other book is entitled Searching for Gold in the Internet. You may reach him at amcf@esoterica.pt. His home page is at http://www.esoterica.pt/amcf/.
Shuman Ghosemajumder is the president of Anadas Software and Internet Development, a leading producer of high-end corporate Web sites and commercial CGI application software. Shuman began in the software industry as a developer of real-time workgroup applications on networked personal computers in the C language. He co-founded Anadas Software and Internet Development in 1995. It now serves clients all over the world. Anadas's head office is in London, Canada. Shuman holds a B.Sc. degree in computer science from the University of Western Ontario.
Ken Hunt is a vice president at Anadas Software and Internet Development. Ken brings to Anadas a wealth of experience in developing software for commercial and scientific applications on many different platforms. His projects have included human blood flow modeling, evolutionary population dynamics, and simulations of the behavior of black holes. An award-winning public speaker, Ken has spoken on the potential of emerging technologies to Fortune 100 companies and university groups in North America and Europe.
Bill Schongar can be found playing multimedia developer and all-purpose Internet guy at LCD Multimedia, in Nashua, NH, doing things like breaking-uh, improving-the systems, helping people find ways to waste their free time, and having fun. When not staring at a computer screen, he can be found in the woods of New Hampshire, being eaten by vicious bugs or trying not to get tagged by paintballs.
Randy Yarger (randy@yarger.tcimet.net) pretends (when the friendly men in white coats let him) he is the systems administrator for H-Net, Humanities OnLine at Michigan State University. He can be reached at http://yarger.tcimet.net/, but please, no sharp objects.
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 |
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: | programming_mgr@sams.mcp.com |
Mail: | Greg Wiegand
Comments Department Sams Publishing 201 W. 103rd Street Indianapolis, IN 46290 |