Before You Begin: Accessing PHP
Creating a Sample Application: Bob’s Auto Parts
Understanding Precedence and Associativity
Using Variable Handling Functions
Testing and Setting Variable Types
Making Decisions with Conditionals
Comparing the Different Conditionals
Repeating Actions Through Iteration
Breaking Out of a Control Structure or Script
Employing Alternative Control Structure Syntax
Storing and Retrieving Bob’s Orders
Opening Files Through FTP or HTTP
Addressing Problems Opening Files
Opening a File for Reading: fopen()
Reading a Line at a Time: fgets()
, fgetss()
, and fgetcsv()
Reading the Whole File: readfile(), fpassthru(), file(), and file_get_contents()
Reading an Arbitrary Length: fread()
Checking Whether a File Is There: file_exists()
Determining How Big a File Is: filesize()
Navigating Inside a File: rewind()
, fseek()
, and ftell()
Problems with Using Flat Files
How RDBMSs Solve These Problems
Initializing Numerically Indexed Arrays
Using Loops to Access the Array
Using asort()
and ksort()
to Sort Arrays
Sorting Multidimensional Arrays
Using the array_multisort()
function
Performing Other Array Manipulations
Navigating Within an Array: each()
, current()
, reset()
, end()
, next()
, pos()
, and prev()
Applying Any Function to Each Element in an Array: array_walk()
Counting Elements in an Array: count()
, sizeof()
, and array_count_values()
Converting Arrays to Scalar Variables: extract()
4 String Manipulation and Regular Expressions
Creating a Sample Application: Smart Form Mail
Trimming Strings: chop()
, ltrim()
, and trim()
Joining and Splitting Strings with String Functions
Using explode()
, implode()
, and join()
Performing String Ordering: strcmp()
, strcasecmp()
, and strnatcmp()
Testing String Length with strlen()
Matching and Replacing Substrings with String Functions
Finding Strings in Strings: strstr()
, strchr()
, strrchr()
, and stristr()
Finding the Position of a Substring: strpos()
and strrpos()
Replacing Substrings: str_replace()
and substr_replace()
Introducing Regular Expressions
Anchoring to the Beginning or End of a String
Matching Literal Special Characters
Putting It All Together for the Smart Form
Finding Substrings with Regular Expressions
Replacing Substrings with Regular Expressions
Splitting Strings with Regular Expressions
5 Reusing Code and Writing Functions
The Advantages of Reusing Code
Using require()
to Include Code
Using require()
for Website Templates
Using auto_prepend_file
and auto_append_file
Understanding Case and Function Names
Examining Basic Function Structure
Passing by Reference Versus Passing by Value
Returning Values from Functions
Implementing Anonymous Functions (or Closures)
Understanding Object-Oriented Concepts
Creating Classes, Attributes, and Operations in PHP
Controlling Access with private
and public
Implementing Inheritance in PHP
Controlling Visibility Through Inheritance with private
and protected
Preventing Inheritance and Overriding with final
Understanding Multiple Inheritance
Writing the Code for Your Class
Understanding Advanced Object-Oriented Functionality in PHP
Checking Class Type and Type Hinting
Overloading Methods with __call()
Implementing Iterators and Iteration
Converting Your Classes to Strings
Understanding the Global Namespace
Importing and Aliasing Namespaces
7 Error and Exception Handling
Exceptions in Bob’s Auto Parts
Exceptions and PHP’s Other Error Handling Mechanisms
Think About the Real-World Objects You Are Modeling
Think About What You Want to Ask the Database
Avoid Designs with Many Empty Attributes
Setting Up Users and Privileges
Introducing MySQL’s Privilege System
User Setup: The CREATE USER
and GRANT
Commands
Types and Levels of Privileges
Examples Using GRANT
and REVOKE
Understanding What the Other Keywords Mean
Understanding the Column Types
Looking at the Database with SHOW
and DESCRIBE
Understanding MySQL Identifiers
10 Working with Your MySQL Database
Inserting Data into the Database
Retrieving Data from the Database
Retrieving Data with Specific Criteria
Retrieving Data from Multiple Tables
Retrieving Data in a Particular Order
Updating Records in the Database
Altering Tables After Creation
Deleting Records from the Database
11 Accessing Your MySQL Database from the Web with PHP
How Web Database Architectures Work
Querying a Database from the Web
Checking and Filtering Input Data
Disconnecting from the Database
Putting New Information in the Database
Using Other PHP-Database Interfaces
Using a Generic Database Interface: PDO
12 Advanced MySQL Administration
Understanding the Privilege System in Detail
The tables_priv
, columns_priv
, and procs priv
Tables
Access Control: How MySQL Uses the Grant Tables
Updating Privileges: When Do Changes Take Effect?
Making Your MySQL Database Secure
MySQL from the Operating System’s Point of View
Getting More Information About Databases
Getting Information About Columns with DESCRIBE
Understanding How Queries Work with EXPLAIN
Backing Up Your MySQL Database
Performing the Initial Data Transfer
Setting Up the Slave or Slaves
The LOAD DATA INFILE
Statement
Understanding Transaction Definitions
Using Transactions with InnoDB
Cursors and Control Structures
14 Web Application Security Risks
Identifying the Threats We Face
Understanding Who We’re Dealing With
Unwitting Users of Infected Machines
15 Building a Secure Web Application
Strategies for Dealing with Security
Balancing Security and Usability
Securing Your Web Server and PHP
Shared Hosting of Web Applications
Users and the Permissions System
Prepare for DoS and DDoS Attacks
Computer and Operating System Security
Keep the Operating System Up to Date
16 Implementing Authentication Methods with PHP
Using Basic Authentication in PHP
Using Basic Authentication with Apache’s .htaccess
Files
Creating Your Own Custom Authentication
17 Interacting with the File System and the Server
Writing the PHP to Deal with the File
Avoiding Common Upload Problems
Getting Information About the Current Directory
Creating and Deleting Directories
Interacting with the File System
Creating, Deleting, and Moving Files
Using Program Execution Functions
Interacting with the Environment: getenv()
and putenv()
18 Using Network and Protocol Functions
Using Data from Other Websites
Using Network Lookup Functions
Backing Up or Mirroring a File
Using FTP to Back Up or Mirror a File
Getting the Date and Time from PHP
Validating Dates with checkdate()
Converting Between PHP and MySQL Date Formats
20 Internationalization and Localization
Localization Is More than Translation
Security Implications of Character Sets
Using Multibyte String Functions in PHP
Creating a Basic Localizable Page Structure
Using gettext()
in an Internationalized Application
Configuring Your System to Use gettext()
Implementing Localized Content in PHP Using gettext()
Setting Up Image Support in PHP
Drawing or Printing Text on the Image
Using Automatically Generated Images in Other Pages
Using Text and Fonts to Create Images
Fitting the Text onto the Button
Writing the Text onto the Button
Drawing Figures and Graphing Data
22 Using Session Control in PHP
Understanding Basic Session Functionality
Unsetting Variables and Destroying the Session
Creating a Simple Session Example
Implementing Authentication with Session Control
23 Integrating JavaScript and PHP
A Brief Introduction to jQuery
Using jQuery in Web Applications
Using jQuery and AJAX with PHP
The AJAX-Enabled Chat Script/Server
The Chat Client/jQuery Application
Terminating Execution: die()
and exit()
Serializing Variables and Objects
Getting Information About the PHP Environment
Finding Out What Extensions Are Loaded
Finding Out When the Script Was Modified
Temporarily Altering the Runtime Environment
V: Building Practical PHP and MySQL Projects
25 Using PHP and MySQL for Large Projects
Applying Software Engineering to Web Development
Planning and Running a Web Application Project
Using a Standard Directory Structure
Documenting and Sharing In-House Functions
Choosing a Development Environment
Altering the Error Reporting Settings
27 Building User Authentication and Personalization
User Identification and Personalization
Implementing User Authentication
Implementing Bookmark Storage and Retrieval
Considering Possible Extensions
28 Building a Web-Based Email Service with Laravel Part I Web Edition
29 Building a Web-Based Email Service with Laravel Part II Web Edition
30 Social Media Integration Sharing and Authentication Web Edition
31 Building a Shopping Cart Web Edition
A Installing Apache, PHP, and MySQL
Installing Apache, PHP, and MySQL Under UNIX
Basic Apache Configuration Modifications
Installing Apache, PHP, and MySQL for Windows and Mac OS X Using All-in-One Installation Packages