Teach Yourself CGI Programming with Perl in a Week

Teach Yourself CGI Programming with Perl in a Week

abcd Learning Sams.net Center Teach Yourself CGI ProgrammingS with Perl S F in a WeekR W EricT Herrmann M 201 West 103rd Street Indianapolis, Indiana 46290 v 009-6 FM 5 1/30/96, 10:12 AM P3/V6/sqc5 TY CGI Prog. in a Week 009-6 maryann 12/15/95 FM LP#3 S F R W abcd Learning How To Use This Book Sams.net Center 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 pro- gramming environment using the Perl language. You get a complete understand- ing 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 on-line catalog. Specific features that you’ll see throughout the book follow. DO Do/Don’t boxes: These give you specific guidance on what to do and DON’T 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 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. Who Should Read 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 andM the Perl language that sets this book apart from others. In addition to helping you develop T an application, you learn the concepts involved in development. W R Conventions Commands, parameters, listings, and on-screen messages appear in a special typeface. Things that you should type appear in boldface. New terms are introduced in italics. i 009-6 FM 1 1/30/96, 10:11 AM P3/V6/sqc5 TY CGI Prog. in a Week 009-6 maryann 12/15/95 FM LP#3 S S F R W T M 7 Teach Yourself CGI Programming with Perl in a Week Wives are great people. They kick you, push you, and hug you when Acquisitions Editor you need it the most. My wife, Sherry, is a great people. She has Mark Taber typed for me, encouraged me, and kept me going when I was most Development Editor tired and grumpy. Thanks for the kicks, the hugs, and the willing- Fran Hatton ness to push when I needed it. I love you. Software Development Specialist Copyright© 1996 by Sams.net Merle Newlon Publishing Production Editor Fran Blauw FIRST EDITION Technical Reviewer All rights reserved. No part of this book shall be reproduced, stored in a Eric Garrison retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the Editorial Coordinator publisher. No patent liability is assumed with respect to the use of the Bill Whitmer information contained herein. Although every precaution has been taken in Technical Edit the preparation of this book, the publisher and author assume no responsi- Coordinator bility for errors or omissions. Neither is any liability assumed for damages Lynette Quinn resulting from the use of the information contained herein. For informa- tion, address Sams.net Publishing, 201 W. 103rd St., Indianapolis, IN Formatter 46290. Frank Sinclair International Standard Book Number: 1-57521-009-6 Editorial Assistant Carol Ackerman Library of Congress Catalog Card Number: 95-70879 Cover Designer 99 98 97 96 4 3 2 1 Jason Grisham Interpretation of the printing code: the rightmost double-digit number is Book Designer the year of the book’s printing; the rightmost single-digit, the number of Alyssa Yesh the book’s printing. For example, a printing code of 96-1 shows that the Production Team first printing of the book occurred in 1996. Supervisor Composed in AGaramond and MCPdigital by Macmillan Computer Brad Chinn Publishing Production Printed in the United States of America Michael Brumitt, Mona Brown, Jeanne Clark, Brad Dixon, Judy Everly, Jason Hand, Trademarks Sonja Hart, Mike Henry, All terms mentioned in this book that are known to be trademarks or Ayanna Lacey, Clint Lahnen, service marks have been appropriately capitalized. Sams.net Publishing Kevin Laseau, Paula Lowell, cannot attest to the accuracy of this information. Use of a term in this book Steph Mineart, Ryan Oldfather, should not be regarded as affecting the validity of any trademark or service Nancy Price, Laura Robbins, mark. Bobbi Satterfield, Dennis Sheehan, Craig Small, Laura Smith, Dan Swenson, Tina Trettin, President, Sams Publishing Richard K. Swadley Susan Van Ness, Mary Beth Publishier, Sams.net Publishing George Bond Wakefield, Todd Wente, Colleen Williams, Jeff Yesh Publishing Manager Mark Taber Indexer Managing Editor Cindy Morrow Brad Herriman Marketing Manager John Pierce vi 009-6 FM 6 1/30/96, 10:12 AM P3/V6/sqc5 TY CGI Prog. in a Week 009-6 maryann 12/15/95 FM LP#3 abcd Learning Overview Sams.net Center Introduction xxi Day 1 Getting Started 1 1 An Introduction to CGI and Its Environment 3 2 Understanding How the Server and Browser Communicate 29 Day 2 Learning the Basics of CGI 61 3 Using Server Side Include Commands 63 S 4 Using Forms to Gather and Send Data 91 Day 3 Understanding CGI Data Management 119 S 5 Decoding Data Sent to Your CGI Program 121 6 Using Environment Variables in Your Programs 157 F Day 4 Putting It All Together 191R 7 Building an On-Line Catalog 193 8 Using Existing CGI LibrariesW 225 Day 5 Using Applications that Make Your Web Page CoolT 267 9 Using Image Maps on Your WebM Page 269 10 Keeping Track of Your Web Page Visitors 299 Day 6 Using Applications that Make Your Web Page Effective 351 11 Using Internet Mail with Your Web Page 353 12 Guarding your Server Against Unwanted Guests 383 Day 7 Looking At Advanced Topics 413 13 Debugging CGI Programs 415 14 Tips, Tricks, and Future Directions 443 Appendixes A MIME Types and File Extensions 461 B HTML Forms 465 C Status Codes and Reason Phrases 479 D The NCSA imagemap.c Program 485 Index 493 vii 009-6 FM 7 1/30/96, 10:13 AM P3/V6/sqc5 TY CGI Prog. in a Week 009-6 maryann 12/15/95 FM LP#3 abcd Learning Sams.net Center Contents Introduction xxi Day 1 Getting Started 1 1 An Introduction to CGI and Its Environment 3 The Common Gateway Interface (CGI)................................................... 5 HTML, HTTP, and Your CGI Program ................................................. 7 The Role of HTML............................................................................. 7 The HTTP Headers ............................................................................ 9 Your CGI Program ............................................................................ 10 S The Directories on Your Server .............................................................. 12 The Server Root ................................................................................ 12 The Document Root ......................................................................... 14 S File Privileges, Permissions, and Protection ............................................ 14 WWW Servers ....................................................................................... 18 F MS-Based Servers .............................................................................. 18 The CERN Server ............................................................................. 19 The NCSA Server..............................................................................R 19 The Netscape Server .......................................................................... 20 The CGI Programming Paradigm .......................................................... 20 CGI Programs and Security ...............................................................W 21 The Basic Data-Passing Methods of CGI .......................................... 21 CGI’s Stateless Environment .............................................................T 22 Preventing the Most Common CGI Bugs .............................................. 23 Tell the Server Your File Is Executable .............................................. 24 Make Your Program ExecutableM ........................................................ 25 Summary................................................................................................ 26 Q&A...................................................................................................... 27 2 Understanding How the Server and Browser Communicate 29 Using the Uniform Resource Identifier .................................................. 30 The Protocol ..................................................................................... 30 The Domain Name ........................................................................... 31 The Directory, File, or CGI Program ...............................................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    492 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