CGI Developer's Guide by Eugene Eric Kim

CGI Developer's Guide by Eugene Eric Kim

CGI Developer's Guide By Eugene Eric Kim Introduction Chapter 1 Common Gateway Interface (CGI) What Is CGI? Caveats Why CGI? Summary Choosing Your Language Chapter 2 The Basics Hello, World! The <form> Tag Dissecting hello.cgi The <input> Tag Hello, World! in C Submitting the Form Outputting CGI Accepting Input from the Browser Installing and Running Your CGI Program Environment Variables Configuring Your Server for CGI GET Versus POST Installing CGI on UNIX Servers Encoded Input Installing CGI on Windows Parsing the Input Installing CGI on the Macintosh A Simple CGI Program Running Your CGI General Programming Strategies A Quick Tutorial on HTML Forms Summary Chapter 3 HTML and Forms A Quick Review of HTML Some Examples HTML Basic Font Tags Comments Form The <head> Tag Ordering Food Forms Voting Booth/Poll The <FORM> Tag Shopping Cart The <INPUT> Tag Map The <SELECT> Tag Summary The <TEXTAREA> Tag Chapter 4 OutPut Revised January 20, 2009 Page 1 of 428 CGI Developer's Guide By Eugene Eric Kim Header and Body: Anatomy of Server Displaying the Current Date Response Server-Side Includes HTTP Headers On-the-Fly Graphics Formatting Output in CGI A "Counter" Example MIME Counting the Number of Accesses Location Text Counter Using Server-Side Includes Status Graphical Counter Other Headers No-Parse Header Dynamic Pages Summary Using Programming Libraries to Code CGI Output Chapter 5 Input Background cgi-lib.pl How CGI Input Works cgihtml Environment Variables Strategies Encoding Scheme An Example: Guestbook GET Versus POST Summary Parsing Strategies and Tools Chapter 6 Programming Strategies Paradigms General Challenges CGI Strategies UNIX File Permissions and Ownership An Enhanced Guestbook Tips and Tricks Practical Programming Summary Chapter 7 Testing and Debugging CGI Debugging Techniques Common Errors Testing Forms Summary Parrot: Echoing the Browser Request Chapter 8 Client/Server Issues Revised January 20, 2009 Page 2 of 428 CGI Developer's Guide By Eugene Eric Kim Client Versus Server HTTP: The Web Server Protocol Accessing an HTML Document Request Submitting a Form Response Accessing a CGI Program Extending the Web Server Redirection Extending the Web Client Authentication Summary Chapter 9 CGI Security Basic Security Issues Shell Dangers Operating Systems Secure Transactions Securing Your Web Server SSL Writing Secure CGI Programs SHTTP Language Risks Summary Chapter 10 Basic Applications Two Small Programs Simple Parser Content Negotiation Customizable Parser (form.cgi) Redirection Manager Using form.cgi as a Guestbook Generic Form Parser Summary Chapter 11 Gateway Using Existing Network Applications True Client/Server Gateways Running a Program Using C Network Programming Parsing the Output in C A Direct Finger Gateway Running a Program Using Perl E-Mail Gateway Parsing the Output in Perl A Simple Mail Program (C) Finger Gateway Extending the Mail Program (Perl) Security Summary Chapter 12 Databases What Is a Database? Database Implementations Revised January 20, 2009 Page 3 of 428 CGI Developer's Guide By Eugene Eric Kim Flat File Online Video Library File System The Database UNIX DBM Query Engine and Annotations Commercial Implementations Administration Tool Search and Retrieval Evaluation Rolodex: A Simple Example Summary Keyword Searches Chapter 13 Multipart Forms and Maintaining State Strategies General Functions Environment Variables Passing State Using URLs Hidden HTML Form Fields Passing State Using Forms Session Files Shopping Carts Multipart Forms Online Course Catalog Tic-Tac-Toe Summary Chapter 14 Proprietary Extensions HTML Extensions Animation Client-Side Imagemaps File Upload Frames Parsing File Upload Client-Side Pull Maintaining State with Cookies Other Extensions Summary Server-Side Push Chapter 15 Imagemaps Server or Client? A Simple Imagemap CGI Imagemaps Using Forms NCSA Imagemap Pretty Tic-Tac-Toe Summary ISMAP Appendix A CGI Reference Output Revised January 20, 2009 Page 4 of 428 CGI Developer's Guide By Eugene Eric Kim Headers ISINDEX MIME Environment Variables No-Parse Header Getting Input from Forms Input Appendix B HTML Guide General Structure Italics Metatags Typewriter Structural Underline Lists Strikeout Preformatted Subscript Division Superscript Center Netscape Extensions Text Formatting Links Headings Inline Multimedia Emphasis Dividers Strong Emphasis Forms Block Quotes Tables Citation Table Rows Address Table Data Source Code Table Headings Sample Output Captions Keyboard Input Frames Variable Frame Elements Definition NOFRAMES Physical Formatting Special Characters Bold Appendix C Server-Side Includes Enabling Server-Side Includes Format and Commands Revised January 20, 2009 Page 5 of 428 CGI Developer's Guide By Eugene Eric Kim config exec echo fsize include flastmod Appendix D cgi-lib.pl Reference Guide Using cgi-lib.pl &MethPost Routines and Variables &MyBaseUrl &ReadParse &MyFullUrl &PrintHeader &CgiError &HtmlTop &CgiDie &HtmlBot &PrintVariables &SplitParam &PrintEnv &MethGet Source Code Appendix E cgihtml Reference Guide Getting Started cgi-lib.h Availability html-lib.h Installing cgihtml llist.h Using cgihtml string-lib.h Compiling Your Program Source Code Routines Credits Copyright © 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-087-8 Revised January 20, 2009 Page 6 of 428 CGI Developer's Guide By Eugene Eric Kim HTML conversion by : M/s. LeafWriters (India) Pvt. Ltd. Website : http://leaf.stpn.soft.net e-mail : [email protected] 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 Manager Mark Taber Managing Editor Cindy Morrow Marketing Manager John Pierce Assistant Marketing Manager Kristina Perry Development Angelique Acquisitions Editor Brad Jones, Sharon Editor Brittingham Software Development Tonya R. Steve Straiger Production Editor Specialist Simpson Bart Reed, Kris Simmons, Stacey Houston, Beth Spencer, Anne Owen, Copy Editor Chuck Hutchinson Editorial Bill Technical Reviewer Justin Bell, Kelly Held, Ian Anderson Coordinator Whitmer Technical Edit Resource Deborah Lynette Quinn Coordinator Coordinator Frisby Carol Ackerman, Andi Formatter Frank Sinclair Editorial Assistants Richter, Rhonda Tinch-Mize, Alyssa Cover Designer Alyssa Yesh Book Designer Yesh Production Team Copy Writer Peter Fuller Brad Chinn Supervisor Gina Brown, Mona Brown, Michael Brumitt, Jeanne Clark, Michael Production Dietsch, Sonja Hart, Mike Henry, Louisa Klucznik, Ayanna Lacey, Chris Livengood, Steph Mineart Author's Acknowledgments The physicist and Nobel Laureate Richard Feynman once tried to prepare a freshman lecture on an obscure topic in physics. Feynman was unable to come up with a satisfactory lecture and suggested that because he was unable to teach it, he really did not understand it. Writing this book helped reveal my own weaknesses and knowledge deficiencies, and I hope I was able to adequately overcome them and write a concise and useful resource. I could not write this book without the aid of many, many others. First, the countless and relatively anonymous souls on the Internet are largely responsible for my knowledge on the topic. Without the Revised January 20, 2009 Page 7 of 428 CGI Developer's Guide By Eugene Eric Kim help of the many who read the newsgroups (especially comp.infosystems.www.authoring.cgi), who provide references on their own World Wide Web sites, and who contribute freely available code for everyone to use, I would never have learned so much so quickly about both the Web and CGI programming. First, I must thank my acquisitions editor at Sams Publishing, Brad Jones, who so patiently put up with my odd and very busy schedule and some late deadlines. Without his patience and belief in me, I would never have had the opportunity to write this book nor the faith to finish it. Thanks to the many others at Sams Publishing as well for their hard work in making this publication a reality. Many odd chains of events led to my interest in this subject and the publication of this book. I must first thank the hard-working student members of the Harvard Computer Society (HCS) for providing me with the resources and opportunity to pursue my interest. Thanks also to the people at the Harvard Arts and Sciences Computer Services (HASCS), especially Mike Burner and Richard Steen, for hiring me to work on the Web at Harvard

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    428 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us