Contents

About the Authors

About the Technical Reviewers

Acknowledgments

Introduction


Chapter 1 Introducing PHP

History

PHP 4

PHP 5

PHP 6

General Language Features

Practicality

Power

Possibility

Price

Summary

Chapter 2 Configuring Your Environment

Installation Prerequisites

Downloading Apache

Downloading PHP

Obtaining the Documentation

Installing Apache and PHP on Linux

Installing Apache and PHP on Windows

Installing IIS and PHP on Windows

Installing IIS and PHP

Configuring FastCGI to Manage PHP Processes

Testing Your Installation

Configuring PHP

Configuring PHP at Build Time on Linux

Customizing the Windows Build

Run-Time Configuration

Managing PHP's Configuration Directives

PHP's Configuration Directives

Choosing a Code Editor

Adobe Dreamweaver CS3

Notepad++

PDT (PHP Development Tools)

Zend Studio

Choosing a Web Hosting Provider

Seven Questions for Any Prospective Hosting Provider

Summary

Chapter 3 PHP Basics

Embedding PHP Code in Your Web Pages

Default Syntax

Short-Tags

Script

ASP Style

Embedding Multiple Code Blocks

Commenting Your Code

Single-Line C++ Syntax

Shell Syntax

Multiple-Line C Syntax

Outputting Data to the Browser

The print() Statement

The printf() Statement

The sprintf() Statement

PHP's Supported Datatypes

Scalar Datatypes

Compound Datatypes

Converting Between Datatypes Using Type Casting

Adapting Datatypes with Type Juggling

Type-Related Functions

Type Identifier Functions

Identifiers

Variables

Variable Declaration

Variable Scope

PHP's Superglobal Variables

Variable Variables

Constants

Expressions

Operands

Operators

String Interpolation

Double Quotes

Single Quotes

Heredoc

Control Structures

Conditional Statements

Looping Statements

File-Inclusion Statements

Summary

Chapter 4 Functions

Invoking a Function

Creating a Function

Passing Arguments by Value

Passing Arguments by Reference

Default Argument Values

Returning Values from a Function

Recursive Functions

Function Libraries

Summary

Chapter 5 Arrays

What Is an Array?

Creating an Array

Creating Arrays with array()

Extracting Arrays with list()

Populating Arrays with a Predefined Value Range

Testing for an Array

Adding and Removing Array Elements

Adding a Value to the Front of an Array

Adding a Value onto the End of an Array

Removing a Value from the Front of an Array

Removing a Value from the End of an Array

Locating Array Elements

Searching an Array

Retrieving Array Keys

Retrieving Array Values

Traversing Arrays

Retrieving the Current Array Key

Retrieving the Current Array Value

Retrieving the Current Array Key and Value

Moving the Array Pointer

Passing Array Values to a Function

Determining Array Size and Uniqueness

Determining the Size of an Array

Counting Array Value Frequency

Determining Unique Array Values

Sorting Arrays

Reversing Array Element Order

Flipping Array Keys and Values

Sorting an Array

Merging, Slicing, Splicing, and Dissecting Arrays

Merging Arrays

Recursively Appending Arrays

Combining Two Arrays

Slicing an Array

Splicing an Array

Calculating an Array Intersection

Calculating Associative Array Intersections

Calculating Array Differences

Calculating Associative Array Differences

Other Useful Array Functions

Returning a Random Set of Keys

Shuffling Array Elements

Summary

Chapter 6 Object-Oriented PHP

The Benefits of OOP

Encapsulation

Inheritance

Polymorphism

Key OOP Concepts

Classes

Objects

Fields

Properties

Constants

Methods

Constructors and Destructors

Constructors

Destructors

Static Class Members

The instanceof Keyword

Helper Functions

Autoloading Objects

Summary

Chapter 7 Advanced OOP Features

Advanced OOP Features Not Supported by PHP

Object Cloning

Cloning Example

The __clone() Method

Inheritance

Class Inheritance

Inheritance and Constructors

Interfaces

Implementing a Single Interface

Implementing Multiple Interfaces

Abstract Classes

Introducing Namespaces

Summary

Chapter 8 Error and Exception Handling

Configuration Directives

Error Logging

Exception Handling

Why Exception Handling Is Handy

PHP's Exception-Handling Implementation

Summary

Chapter 9 Strings and Regular Expressions

Regular Expressions

Regular Expression Syntax (POSIX)

PHP's Regular Expression Functions (POSIX Extended)

Regular Expression Syntax (Perl)

Other String-Specific Functions

Determining the Length of a String

Comparing Two Strings

Manipulating String Case

Converting Strings to and from HTML

Alternatives for Regular Expression Functions

Padding and Stripping a String

Counting Characters and Words

Taking Advantage of PEAR: Validate_US

Installing Validate_US

Using Validate_US

Summary

Chapter 10 Working with the File and Operating System

Learning About Files and Directories

Parsing Directory Paths

Calculating File, Directory, and Disk Sizes

Determining Access and Modification Times

Working with Files

The Concept of a Resource

Recognizing Newline Characters

Recognizing the End-of-File Character

Opening and Closing a File

Reading from a File

Writing a String to a File

Moving the File Pointer

Reading Directory Contents

Executing Shell Commands

System-Level Program Execution

Sanitizing the Input

PHP's Program Execution Functions

Summary

Chapter 11 PEAR

Popular PEAR Packages

Preinstalled Packages

Installer-Suggested Packages

The Power of PEAR: Converting Numeral Formats

Installing and Updating PEAR

Installing PEAR

PEAR and Hosting Companies

Updating PEAR

Using the PEAR Package Manager

Viewing an Installed PEAR Package

Learning More About an Installed PEAR Package

Installing a PEAR Package

Including a Package Within Your Scripts

Upgrading Packages

Uninstalling a Package

Downgrading a Package

Summary

Chapter 12 Date and Time

The Unix Timestamp

PHP's Date and Time Library

Validating Dates

Formatting Dates and Times

Converting a Timestamp to User-Friendly Values

Working with Timestamps

Date Fu

Displaying the Localized Date and Time

Displaying the Web Page's Most Recent Modification Date

Determining the Number of Days in the Current Month

Determining the Number of Days in Any Given Month

Calculating the Date X Days from the Present Date

Taking Advantage of PEAR: Creating a Calendar

Date and Time Enhancements for PHP 5.1+ Users

Introducing the DateTime Constructor

Formatting Dates

Setting the Date After Instantiation

Setting the Time After Instantiation

Modifying Dates and Times

Summary

Chapter 13 Forms

PHP and Web Forms

A Simple Example

Passing Form Data to a Function

Working with Multivalued Form Components

Taking Advantage of PEAR: HTML_QuickForm

Installing HTML_QuickForm

Creating a Simple Form

Using Auto-Completion

Summary

Chapter 14 Authenticating Your Users

HTTP Authentication Concepts

PHP Authentication

Authentication Variables

Useful Functions

PHP Authentication Methodologies

Hard-Coded Authentication

File-based Authentication

Database-based Authentication

IP-based Authentication

Taking Advantage of PEAR: Auth_HTTP

User Login Administration

Testing Password Guessability with the CrackLib Library

One-Time URLs and Password Recovery

Summary

Chapter 15 Handling File Uploads

Uploading Files via HTTP

Uploading Files with PHP

PHP's File Upload/Resource Directives

The $_FILES Array

PHP's File-Upload Functions

Upload Error Messages

A Simple Example

Taking Advantage of PEAR: HTTP_Upload

Installing HTTP_Upload

Uploading a File

Learning More About an Uploaded File

Uploading Multiple Files

Summary

Chapter 16 Networking

DNS, Services, and Servers

DNS

Services

Establishing Socket Connections

Mail

Configuration Directives

Sending E-mail Using a PHP Script

Common Networking Tasks

Pinging a Server

Creating a Port Scanner

Creating a Subnet Converter

Testing User Bandwidth

Summary

Chapter 17 PHP and LDAP

Using LDAP from PHP

Connecting to an LDAP Server

Retrieving LDAP Data

Counting Retrieved Entries

Sorting LDAP Records

Inserting LDAP Data

Updating LDAP Data

Deleting LDAP Data

Working with the Distinguished Name

Error Handling

Summary

Chapter 18 Session Handlers

What Is Session Handling?

The Session-Handling Process

Configuration Directives

Managing the Session Storage Media

Setting the Session Files Path

Automatically Enabling Sessions

Setting the Session Name

Choosing Cookies or URL Rewriting

Automating URL Rewriting

Setting the Session Cookie Lifetime

Setting the Session Cookie's Valid URL Path

Setting Caching Directions for Session-Enabled Pages

Working with Sessions

Starting a Session

Destroying a Session

Setting and Retrieving the Session ID

Creating and Deleting Session Variables

Encoding and Decoding Session Data

Practical Session-Handling Examples

Automatically Logging In Returning Users

Generating a Recently Viewed Document Index

Creating Custom Session Handlers

Tying Custom Session Functions into PHP's Logic

Using Custom MySQL-Based Session Handlers

Summary

Chapter 19 Templating with Smarty

What's a Templating Engine?

Introducing Smarty

Installing Smarty

Using Smarty

Smarty's Presentational Logic

Comments

Variable Modifiers

Control Structures

Statements

Creating Configuration Files

config_load

Referencing Configuration Variables

Using CSS in Conjunction with Smarty

Caching

Working with the Cache Lifetime

Eliminating Processing Overhead with is_cached()

Creating Multiple Caches per Template

Some Final Words About Caching

Summary

Chapter 20 Web Services

Why Web Services?

Really Simple Syndication

Understanding RSS Syntax

Introducing MagpieRSS

SimpleXML

Loading XML

Parsing XML

SOAP

Introducing SOAP Messages

Introducing PHP's SOAP Extension

Summary

Chapter 21 Secure PHP Programming

Configuring PHP Securely

Safe Mode

Other Security-Related Configuration Parameters

Hiding Configuration Details

Hiding Apache

Hiding PHP

Hiding Sensitive Data

Hiding the Document Root

Denying Access to Certain File Extensions

Sanitizing User Data

File Deletion

Cross-Site Scripting

Sanitizing User Input: The Solution

Taking Advantage of PEAR: Validate

Data Encryption

PHP's Encryption Functions

The MCrypt Package

Summary

Chapter 22 SQLite

Introduction to SQLite

Installing SQLite

Using the SQLite Command-Line Interface

PHP's SQLite Library

sqlite.assoc_case = 0 | 1 | 2

Opening a Connection

Creating a Table in Memory

Closing a Connection

Querying a Database

Parsing Result Sets

Retrieving Result Set Details

Manipulating the Result Set Pointer

Retrieving a Table's Column Types

Working with Binary Data

Creating and Overriding SQLite Functions

Creating Aggregate Functions

Summary

Chapter 23 Building Web Sites for the World

Translating Web Sites with Gettext

Step 1: Update the Web Site Scripts

Step 2: Create the Localization Repository

Step 3: Create the Translation Files

Step 4: Translate the Text

Step 5: Generate Binary Files

Step 6: Set the Desired Language Within Your Scripts

Localizing Dates, Numbers, and Times

Summary

Chapter 24 MVC and the Zend Framework

Introducing MVC

PHP's Framework Solutions

The CakePHP Framework

The Solar Framework

The symfony Framework

The Zend Framework

Introducing the Zend Framework

Downloading and Installing the Zend Framework

Creating Your First Zend Framework-Driven Web Site

Searching the Web with Zend_Service_Yahoo

Summary

Chapter 25 Introducing MySQL

What Makes MySQL So Popular?

Flexibility

Power

Flexible Licensing Options

A (Hyper) Active User Community

The Evolution of MySQL

MySQL 4

MySQL 5.0

MySQL 5.1

Prominent MySQL Users

craigslist

Wikipedia

Yahoo! Finance

Summary

Chapter 26 Installing and Configuring MySQL

Downloading MySQL

Downloading MySQL for Windows

Installing MySQL

Installing MySQL on Linux

Installing and Configuring MySQL on Windows

Setting the MySQL Administrator Password

Starting and Stopping MySQL

Controlling the Daemon Manually

Starting and Stopping MySQL Automatically

Configuring and Optimizing MySQL

The mysqld_safe Wrapper

MySQL's Configuration and Optimization Parameters

The my.cnf File

Configuring PHP to Work with MySQL

Reconfiguring PHP on Linux

Reconfiguring PHP on Windows

Summary

Chapter 27 The Many MySQL Clients

Introducing the Command-Line Clients

The mysql Client

The mysqladmin Client

Other Useful Clients

Client Options

MySQL's GUI Client Programs

Installing GUI Tools

MySQL Administrator

MySQL Query Browser

MySQL Migration Toolkit

phpMyAdmin

Summary

Chapter 28 MySQL Storage Engines and Datatypes

Storage Engines

MyISAM

InnoDB

MEMORY

MERGE

FEDERATED

ARCHIVE

CSV

EXAMPLE

BLACKHOLE

Storage Engine FAQ

Datatypes and Attributes

Datatypes

Datatype Attributes

Working with Databases and Tables

Working with Databases

Working with Tables

Altering a Table Structure

The INFORMATION_SCHEMA

Summary

Chapter 29 Securing MySQL

What You Should Do First

Securing the mysqld Daemon

The MySQL Access Privilege System

How the Privilege System Works

Where Is Access Information Stored?

User and Privilege Management

Creating Users

Deleting Users

Renaming Users

The GRANT and REVOKE Commands

Reviewing Privileges

Limiting User Resources

Secure MySQL Connections

Grant Options

SSL Options

Starting the SSL-Enabled MySQL Server

Connecting Using an SSL-Enabled Client

Storing SSL Options in the my.cnf File

Summary

Chapter 30 Using PHP with MySQL

Handling Installation Prerequisites

Enabling the mysqli Extension on Linux/Unix

Enabling the mysqli Extension on Windows

Managing User Privileges

Working with Sample Data

Using the mysqli Extension

Setting Up and Tearing Down the Connection

Handling Connection Errors

Retrieving Error Information

Storing Connection Information in a Separate File

Securing Your Connection Information

Interacting with the Database

Sending a Query to the Database

Parsing Query Results

Determining the Rows Selected and Rows Affected

Working with Prepared Statements

Executing Database Transactions

Enabling Autocommit Mode

Committing a Transaction

Rolling Back a Transaction

Summary

Chapter 31 Introducing PDO

Another Database Abstraction Layer?

Using PDO

Installing PDO

PDO's Database Options

Connecting to a Database Server and Selecting a Database

Handling Errors

Getting and Setting Attributes

Executing Queries

Introducing Prepared Statements

Retrieving Data

Setting Bound Columns

Working with Transactions

Summary

Chapter 32 Stored Routines

Should You Use Stored Routines?

Stored Routine Advantages

Stored Routine Disadvantages

How MySQL Implements Stored Routines

Stored Routine Privilege Tables

Creating a Stored Routine

Declaring and Setting Variables

Executing a Stored Routine

Creating and Using Multistatement Stored Routines

Calling a Routine from Within Another Routine

Modifying a Stored Routine

Deleting a Stored Routine

Viewing a Routine's Status

Viewing a Routine's Creation Syntax

Handling Conditions

Integrating Routines into Web Applications

Creating the Employee Bonus Interface

Retrieving Multiple Rows

Summary

Chapter 33 MySQL Triggers

Introducing Triggers

Why Use Triggers?

Taking Action Before an Event

Taking Action After an Event

Before Triggers vs. After Triggers

MySQL's Trigger Support

Creating a Trigger

Viewing Existing Triggers

Modifying a Trigger

Deleting a Trigger

Integrating Triggers into Web Applications

Summary

Chapter 34 MySQL Views

Introducing Views

MySQL's View Support

Creating and Executing Views

Viewing View Information

Modifying a View

Deleting a View

Updating Views

Incorporating Views into Web Applications

Summary

Chapter 35 Practical Database Queries

Sample Data

Creating Tabular Output with PEAR

Installing HTML_Table

Creating a Simple Table

Creating More Readable Row Output

Creating a Table from Database Data

Generalizing the Output Process

Sorting Output

Creating Paged Output

Listing Page Numbers

Querying Multiple Tables with Subqueries

Performing Comparisons with Subqueries

Determining Existence with Subqueries

Performing Database Maintenance with Subqueries

Using Subqueries with PHP

Iterating Result Sets with Cursors

Cursor Basics

Creating a Cursor

Opening a Cursor

Using a Cursor

Closing a Cursor

Using Cursors with PHP

Summary

Chapter 36 Indexes and Searching

Database Indexing

Primary Key Indexes

Unique Indexes

Normal Indexes

Full-Text Indexes

Indexing Best Practices

Forms-Based Searches

Performing a Simple Search

Extending Search Capabilities

Performing a Full-Text Search

Summary

Chapter 37 Transactions

What's a Transaction?

MySQL's Transactional Capabilities

System Requirements

Table Creation

A Sample Project

Creating Tables and Adding Sample Data

Executing an Example Transaction

Backing Up and Restoring InnoDB Tables

Usage Tips

Building Transactional Applications with PHP

The Swap Meet Revisited

Summary

Chapter 38 Importing and Exporting Data

Sample Table

Using Data Delimitation

Importing Data

Importing Data with LOAD DATA INFILE

Importing Data with mysqlimport

Loading Table Data with PHP

Exporting Data

SELECT INTO OUTFILE

Summary


Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.10.69