You are previewing Sams Teach Yourself CGI in 24 Hours, Second Edition.
O'Reilly logo
Sams Teach Yourself CGI in 24 Hours, Second Edition

Book Description

Sams Teach Yourself CGI in 24 Hours teaches the reader the next step beyond simple HTML Web pages. This new edition covers implementing CGI with both C and Perl, and it discusses CGI¿s relative strengths and weaknesses in comparison with other Web programming technologies like JavaScript, Java, and PHP. It also covers recent developments in templating systems and mod_perl server add-ons.

The book takes the reader from the basics of CGI¿learning, for example, how to implement and customize existing CGI programs that have been written by others¿to the point where he can use CGI to create his own programs from scratch.

The book also provides numerous real-life examples of CGI scripts¿database search tools, survey forms, interactive games, order forms, guest books, and more.

Table of Contents

  1. Copyright
  2. About the Author
  3. Acknowledgments
  4. We Want to Hear from You!
  5. Reader Services
  6. Introduction
  7. An Introduction to CGI
    1. Overview of CGI Programming
      1. Types of Web Applications
      2. A History of CGI
      3. What Is a CGI Program?
      4. How CGI Programs Work
      5. Pros and Cons of CGI
      6. CGI Programming Languages
      7. Summary
      8. Q&A
      9. Workshop
    2. Setting Up Your CGI Environment
      1. The Web Server Itself
      2. Web-Server Operating Systems
      3. The CGI Environment
      4. Web Servers
      5. Setting Up Your CGI Development Environment
      6. Summary
      7. Q&A
      8. Workshop
    3. Downloading, Installing, and Debugging CGI Scripts
      1. Downloading Scripts from the Internet
      2. Installing a Downloaded Script
      3. Example: Downloading and Installing a Guestbook Script
      4. Debugging CGI Scripts
      5. Tools and Techniques for Debugging Your Program Code
      6. Summary
      7. Q&A
      8. Workshop
    4. Writing Your First CGI Program
      1. Parts of CGI Programs
      2. A URL-Redirection Program
      3. How File Redirection Works
      4. Working with Files in Perl
      5. Common Statements Used in Perl
      6. The if Statement
      7. Perl Expressions
      8. Summary
      9. Q&A
      10. Workshop
  8. Capturing User Input
    1. Creating HTML Forms
      1. The <form> Tag
      2. The <input> Tag
      3. Other Form Fields
      4. Workshop: Building an Entire Form
      5. Summary
      6. Q&A
      7. Workshop
    2. Working with HTTP
      1. HTTP Basics
      2. What Takes Place During an HTTP Session
      3. Request Methods
      4. Server Response Codes
      5. Response Headers
      6. NPH Scripts
      7. Content Types
      8. Secure Connections
      9. Summary
      10. Q&A
      11. Workshop
    3. Validating User Input
      1. Using JavaScript for Form Validation
      2. Designing Easily Validated Forms
      3. Incorporating Validation into the Form-Processing Code
      4. An Example of Form Processing
      5. Validating Values
      6. Summary
      7. Q&A
      8. Workshop
    4. Creating an Email Feedback Form
      1. What Kinds of Applications Involve Sending Email?
      2. How Email Works
      3. Example: Sending Email from a CGI Script
      4. Summary
      5. Q&A
      6. Workshop
  9. CGI Programming Languages and Tools
    1. Web Application Architecture
      1. Application Design
      2. Round-trip Scripts
      3. Declarative Programming
      4. Handling Many Types of Requests
      5. Sharing Code Among Scripts
      6. Using CGI::Application
      7. Summary
      8. Workshop
    2. Delving Further into Perl
      1. CGI.pm
      2. Accessing CGI.pm from Your Program
      3. Decoding Form Data via CGI.pm
      4. Generating HTTP Headers and HTML Tags via CGI.pm
      5. cgi-lib.pl
      6. Handling Errors with CGI::Carp
      7. Resources for Perl Programmers
      8. Summary
      9. Q&A
      10. Workshop
    3. Other Popular CGI Programming Languages
      1. Will My Favorite Language Work for CGI?
      2. Writing CGI Programs Using the Bourne Shell
      3. Creating Gateways to UNIX Commands
      4. Working with Query Strings
      5. Writing CGI Programs in C
      6. The cgic Library
      7. A C Example
      8. Writing CGI Programs in Python
      9. A Python Example
      10. Summary
      11. Q&A
      12. Workshop
    4. Pros and Cons of Alternate Technologies
      1. Looking Back
      2. J2EE
      3. PHP
      4. ASP.NET
      5. Macromedia ColdFusion
      6. The Apache mod_perl Module
      7. Summary
      8. Q&A
      9. Workshop
  10. Building Basic CGI Applications
    1. Using Flat Files for Data Storage
      1. What Is a Database?
      2. Flat-File Databases
      3. File Operations
      4. Building a Database Application
      5. Summary
      6. Q&A
      7. Workshop
    2. Creating a CGI-Based Message Board
      1. The Structure of the Application
      2. The File Format
      3. The Display Script
      4. The Posting Script
      5. Summary
      6. Q&A
      7. Workshop
    3. Session Management
      1. Why Use Session Management?
      2. Basic Authentication
      3. Hidden Fields in Forms
      4. Hidden Form Fields Example
      5. Using Cookies
      6. Session Management with Cookies
      7. Summary
      8. Q&A
      9. Workshop
    4. Building a Simple Shopping Cart
      1. How the Sample Shopping Cart Works
      2. The Catalog
      3. The Contents of the Shopping Cart
      4. Checkout
      5. Summary
      6. Q&A
      7. Workshop
    5. Content Management with CGI
      1. Why Content Publishing?
      2. Types of Content Publishing Systems
      3. Data Storage for Content Publishing Systems
      4. A Content Publishing Example
      5. Free Content Management Systems
      6. Summary
      7. Q&A
      8. Workshop
  11. Integrating Databases with CGI
    1. Working with Relational Databases
      1. The Relational Database Model
      2. Structured Query Language
      3. Database Design
      4. Relational Data Types
      5. Summary
      6. Q&A
      7. Workshop
    2. How to Use the Structured Query Language
      1. Structured Query Language
      2. Database Interfaces
      3. Summary
      4. Q&A
      5. Workshop
    3. Creating an Online Store
      1. The Database Design
      2. The Catalog Script
      3. The Shopping Cart Script
      4. The Checkout Script
      5. Summary
      6. Q&A
      7. Workshop
  12. Additional CGI Tips and Tricks
    1. Handling Other Content Types
      1. Content Types
      2. Handling Binary Content
      3. An Authenticated Download Application
      4. Creating Your Own Ad Server
      5. Tracking User Activity
      6. Summary
      7. Q&A
      8. Workshop
    2. Securing CGI Scripts
      1. Why Security?
      2. Securing Your Web Server
      3. Common CGI Security Holes
      4. Safe Programming
      5. Summary
      6. Q&A
      7. Workshop
    3. Creating Custom Error Documents
      1. What Is an Error Document?
      2. Configuring Your Web Server for Custom Error Documents
      3. Using HTML to Create a Basic Error Document
      4. Using CGI to Create an Advanced Error Document
      5. Handling an “Unauthorized” Error
      6. Summary
      7. Q&A
      8. Workshop
    4. Server Side Includes
      1. How Server Side Includes Work
      2. Setting Up Your Web Server for SSI
      3. Using SSI Directives
      4. Designing Pages Using SSI
      5. XSSI
      6. Summary
      7. Q&A
      8. Workshop
  13. Appendixes
    1. MIME Types
    2. Response Codes and Reason Phrases
    3. Environment Variables and Request Headers
      1. CGI Environment Variables
      2. HTTP Request Headers
    4. Summary of Regular Expressions
    5. ASCII Table
  14. Index