Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Gunther Birznieks, Shishir Gundavaram, Scott Guelich
CGI Programming with Perl, 2nd Edition
CGI Programming with Perl, 2nd Edition
A Note Regarding Supplemental Files
Preface
What’s in the Book
What You Are Expected to Know Before Reading
Overview of the Book
Conventions in This Book
How to Contact Us
Acknowledgments
Acknowledgments from the First Edition
1. Getting Started
History
How CGI Is Used Today
Introduction to CGI
Sample CGI
Invoking CGI Scripts
Alternative Technologies
Why Perl?
Alternatives to CGI
Web Server Configuration
Configuring CGI Scripts
Configuring by directory
Configuring by extension
2. The Hypertext Transport Protocol
URLs
Elements of a URL
Absolute and Relative URLs
URL Encoding
HTTP
The Request and Response Cycle
HTTP Headers
HTTP 1.1 and HTTP 1.0
Browser Requests
The Request Line
PUT and DELETE
GET
HEAD
POST
Request Header Field Lines
Host
Content-Length
Content-Type
Authorization
User-Agent
Accept
Referer
Cookies
Server Responses
The Status Line
Server Headers
Content-Base
Content-Length
Content-Type
Date
ETag
Last-Modified
Location
Server
Set-Cookie
WWW-Authenticate
Proxies
Identifying Clients
Caching
Content Negotiation
Media Type
Internationalization
Encoding
Summary
3. The Common Gateway Interface
The CGI Environment
File Handles
STDIN
STDOUT
STDERR
Environment Variables
CGI Environment Variables
Examining Environment Variables
CGI Output
Partial Headers
Outputting documents
Forwarding to another URL
Specifying status codes
Complete (Non-Parsed) Headers
Examples
Check the Client Browser
User Authentication and Identification
Restricting Image Hijacking
4. Forms and CGI
Sending Data to the Server
Form Tags
Quick Reference to Form Tags
The <FORM> Tag
The <INPUT> Tag
Text fields
Password fields
Hidden fields
Checkboxes
Radio buttons
Submit buttons
Reset buttons
Image buttons
Plain buttons
The <SELECT> Tag
The <OPTION> tag
The <TEXTAREA> Tag
Decoding Form Input
5. CGI.pm
Overview
Denial of Service Attacks
The Kitchen Sink
Standard and Object-Oriented Syntax
Handling Input with CGI.pm
Environment Information
Accept
http
https
query_string
self_url
url
virtual_host
Accessing Parameters
Modifying parameters
POST and the query string
Index queries
Supporting image buttons as submit buttons
Exporting Parameters to a Namespace
File Uploads with CGI.pm
Generating Output with CGI.pm
Controlling HTTP Headers with CGI.pm
Media type
Status
Caching
Specifying an alternative target
Redirection
Other headers
Starting and Ending Documents
start_html
end_html
Standard HTML Elements
Form Elements
Alternatives for Generating Output
Lots of print Statements
Here Documents
Handling Errors
Dying Gracefully
Trapping die
CGI::Carp
Error Subroutines
Custom Module
6. HTML Templates
Reasons for Using Templates
Rolling Your Own
Server Side Includes
Configuration
Format
Environment Variables
Tailoring SSI Output
Including Boilerplates
Executing CGI Programs
Common Errors
HTML::Template
Syntax
Loops
Conditionals
Including other files
Summary
Embperl
Configuration
Execute
mod_perl
embpcgi.pl
Syntax
Embperl code blocks
Variable scope
Meta-commands
HTML Logic
Tables
List elements
Form input elements
Global Variables
Example
Embperl handler
Summary
Mason
A Component Approach
7. JavaScript
Background
History
Compatibility
Forms
Input Validation
Validating elements
Validating submits
Validation example
Validating twice
Data Exchange
WDDX
Example
Bookmarklets
Bookmarklet Basics
Compatibility
Bookmarklets and CGI
8. Security
The Importance of Web Security
Handling User Input
Calling External Applications
User Input and the Shell
Security Strategies
fork and exec
Trusting the Browser
Encryption
MD5
SHA-1
Perl’s Taint Mode
How Taint Works
What Is Monitored by Taint Mode
How Taintedness Is Removed
Allowing versus disallowing
Why Use Taint Mode?
Common Problems with Taint Mode
Data Storage
Dynamic Filenames
Location of Files
File Permissions
Summary
9. Sending Email
Security
Mailers and Shells
False Identities
Spam
Email Addresses
Validating Syntax
Structure of Internet Email
sendmail
Command-Line Options
Mail Queue
mailx and mail
Perl Mailers
procmail
Autoreply from nobody
Forwarding to Another User
10. Data Persistence
Text Files
Locking
flock
Manual lock files
Write Permissions
Temporary Files
Anonymous temporary files
Named temporary files
Delimiters
DBD::CSV
DBM Files
DB_File
MLDBM
Introduction to SQL
Creating a Database
Inserting Data
Accessing Data
Updating Data
Deleting Data
DBI
Using DBI
Connecting to DBI
Database manipulation
Database querying
DBI Address Book
Address book database creation script
Address book CGI script
11. Maintaining State
Query Strings and Extra Path Information
Hidden Fields
Client-Side Cookies
Setting Cookies
Testing for Cookies
12. Searching the Web Server
Searching One by One
Searching One by One, Take Two
Regex-Based Search Engine
Inverted Index Search
Search Application
13. Creating Graphics on the Fly
File Formats
GIF
The LZW patent
PNG
JPEG
PDF
Outputting Image Data
An Example
binmode
Including Dynamic Images in HTML
Redundant path information
Preventing caching
Generating PNGs with GD
Installation
Using GD
Additional GD Modules
GD::Text
GD::Text::Align
GD::Graph
GD::Graph3D
PerlMagick
Installation
Requirements
Enabling LZW compression
Converting PNGs to GIFs or JPEGs
PDF and PostScript Support
Image Processing
14. Middleware and XML
Communicating with Other Servers
Sockets
IO::Socket
LWP
An Introduction to XML
Document Type Definition
Writing an XML Parser
CGI Gateway to XML Middleware
15. Debugging CGI Applications
Common Errors
Application Permissions
The Pound-Bang
Line Endings
“Malformed” Header
Perl Coding Techniques
Use strict
Check Status of System Calls
Is It Open?
Trap die
File Locking
Unbuffer Output Stream
Use binmode
Debugging Tools
Check Syntax
Check Error Logs
Running Scripts from the Command Line
Dumping Variables
Debuggers
The Perl debugger
ptkdb
ActiveState Perl debugger
16. Guidelines for Better CGI Applications
Architectural Guidelines
Plan for Future Growth
Use Directories to Organize Your Projects
Use Relative URLs
Separate Configuration from Your Primary Code
Separating Display from Your Primary Code
Separating Storage from Your Primary Code
Number of Scripts per Application
Using one CGI program rather than many for each major application
Using multiple CGI scripts for each major application
Using Submit Buttons to Control Flow
Coding Guidelines
17. Efficiency and Optimization
Basic Perl Tips, Top Ten
Benchmark Your Code
Benchmark Modules, Too
Localize Variables with my
Avoid Slurping
undef Versus ( )
SelfLoader
autouse
Avoid the Shell
Find Existing Solutions for Your Problems
Regular Expressions
FastCGI
Installing FastCGI
mod_perl
Installation and Configuration
mod_perl Considerations
A. Works Cited and Further Reading
References
Additional Reading
RFCs
Other Specifications
Project Home Pages
Newsgroups
B. Perl Modules
CPAN
Installing Modules
perldoc
Index
About the Authors
Colophon
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
CGI Programming with Perl, 2nd Edition
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset