McLaughlin, B. (2012) PHP and MySQL – The Missing Manual, Second Edition, O’Reilly Media, Inc
Download eBook PDF (PDF 11,274KB)
Download Source Code (ZIP 2.052KB)
Download Missing CD (ZIP 2,098KB)
If you can build websites with CSS and JavaScript, this book takes you to the next level—creating dynamic, database-driven websites with PHP and MySQL. Learn how to build a database, manage your content, and interact with users. With step-by-step tutorials, this completely revised edition gets you started with expanded coverage of the basics and takes you deeper into the world of server-side programming.
The important stuff you need to know:
- Get up to speed quickly. Learn how to install PHP and MySQL, and get them running on both your computer and a remote server.
- Gain new techniques. Take advantage of the all-new chapter on integrating PHP with HTML web pages.
- Manage your content. Use the file system to access user data, including images and other binary files.
- Make it dynamic. Create pages that change with each new viewing.
- Build a good database. Use MySQL to store user information and other data.
- Keep your site working. Master the tools for fixing things that go wrong.
- Control operations. Create an administrative interface to oversee your site.
Table of Contents
Introduction;
What PHP and MySQL Can Do;
What Is PHP?;
What Is MySQL?;
Part 1: PHP and MySQL Basics;
Chapter 1: PHP: What, Why, and Where?;
1.1 PHP Comes in Two Flavors: Local and Remote;
1.2 PHP: Going Local;
1.3 Write Your First Program;
1.4 Run Your First Program;
1.5 But Where’s That Web Server?;
Chapter 2: PHP Meets HTML;
2.1 Script or HTML?; 2.2 PHP Talks Back;
2.3 Run PHP Scripts Remotely;
Chapter 3: PHP Syntax: Weird and Wonderful;
3.1 Get Information from a Web Form;
3.2 Working with Text in PHP;
3.3 The $_REQUEST Variable Is an Array;
3.4 What Do You Do with User Information?;
Chapter 4: MySQL and SQL: Database and Language;
4.1 What Is a Database?;
4.2 Installing MySQL;
4.3 SQL Is a Language for Talking to Databases;
Part 2: Dynamic Web Pages;
Chapter 5: Connecting PHP to MySQL;
5.1 Writing a Simple PHP Connection Script;
5.2 Cleaning Up Your Code with Multiple Files;
5.3 Building a Basic SQL Query Runner;
Chapter 6: Regular Expressions;
6.1 String Matching, Double-Time;
Chapter 7: Generating Dynamic Web Pages;
7.1 Revisiting a User’s Information;
7.2 Planning Your Database Tables;
7.3 Saving a User’s Information;
7.4 Show Me the User;
7.5 Revisiting (and Redirecting) the Create User Script;
Part 3: From Web Pages to Web Applications;
Chapter 8: When Things Go Wrong (and They Will);
8.1 Planning Your Error Pages;
8.2 Finding a Middle Ground for Error Pages with PHP;
8.3 Add Debugging to Your Application;
8.4 Redirecting On Error;
Chapter 9: Handling Images and Complexity;
9.1 Images Are Just Files;
9.2 Images Are for Viewing;
9.3 And Now for Something Completely Different;
Chapter 10: Binary Objects and Image Loading;
10.1 Storing Different Objects in Different Tables;
10.2 Inserting a Raw Image into a Table;
10.3 Your Binary Data Isn’t Safe to Insert…Yet;
10.4 Connecting Users and Images;
10.5 Show Me the Image!;
10.6 Embedding an Image Is Just Viewing an Image;
10.7 So, Which Approach Is Best?;
Chapter 11: Listing, Iterating, and Administrating;
11.1 Thinking about What You Need as an Admin;
11.2 Listing All Your Users;
11.3 Deleting a User;
11.4 Talking Back to Your Users;
11.5 Standardizing on Messaging;
11.6 Integrating Utilities, Views, and Messages;
Part 4: Security and the Real World;
Chapter 12: Authentication and Authorization;
12.1 Basic Authentication;
12.2 Abstracting What’s the Same;
12.3 Passwords Don’t Belong in PHP Scripts;
12.4 Passwords Create Security, But Should Be Secure;
Chapter 13: Cookies, Sign-Ins, and Ditching Crummy Pop-Ups;
13.1 Moving Beyond Basic Authentication;
13.2 Logging In with Cookies;
13.3 Adding Context-Specific Menus;
Chapter 14: Authorization and Sessions;
14.1 Modeling Groups in Your Database;
14.2 Checking for Group Membership;
14.3 Group-Specific Menus;
14.4 Entering Browser Sessions;
14.5 Memory Lane: Remember That Phishing Problem?;
14.6 Why Would You Ever Use Cookies?;
Part 5: Appendixes;
Installing PHP on Windows Without WAMP;
Installing PHP from www.php.net;
Installing MySQL Without MAMP or WAMP;
Installing MySQL;
- The Missing Credits
- Introduction
- Part 1: PHP and MySQL Basics
- Chapter 1: PHP: What, Why, and Where?
- Chapter 2: PHP Meets HTML
- Chapter 3: PHP Syntax: Weird and Wonderful
- Chapter 4: MySQL and SQL: Database and Language
- Part 2: Dynamic Web Pages
- Chapter 5: Connecting PHP to MySQL
- Chapter 6: Regular Expressions
- Chapter 7: Generating Dynamic Web Pages
- Part 3: From Web Pages to Web Applications
- Chapter 8: When Things Go Wrong (and They Will)
- Chapter 9: Handling Images and Complexity
- Chapter 10: Binary Objects and Image Loading
- Chapter 11: Listing, Iterating, and Administrating
- Part 4: Security and the Real World
- Chapter 12: Authentication and Authorization
- Chapter 13: Cookies, Sign-Ins, and Ditching Crummy Pop-Ups
- Chapter 14: Authorization and Sessions
- Part 5: Appendixes
- Installing PHP on Windows Without WAMP
- Installing MySQL Without MAMP or WAMP
Nixon, R. (2009) Learning PHP, MySQL and JavaScript, O’Reilly Media, Inc.
A more recent version of this book is available
Download eBook PDF (PDF 9.814KB)
Download Source Code (ZIP 120KB)
Companion Website: http://lpmj.net/1stedition/
Learning PHP, MySQL and JavaScript will teach you how to create responsive, data-driven websites with the three central technologies of PHP, MySQL and JavaScript – whether or not you know how to program. This simple, streamlined guide explains how the powerful combination of PHP and MySQL provides a painless way to build modern websites with dynamic data and user interaction. You’ll also learn how to add JavaScript to create rich Internet websites and applications, and how to use Ajax to handle background communication with a web server.
This book explains each technology separately, shows you how to combine them, and introduces valuable concepts in modern web programming, including objects, XHTML, cookies, regular expressions and session management. Learning PHP, MySQL and JavaScript will help you:
- Understand the essentials of PHP and the basics of object-oriented programming
- Master MySQL, from database structure to complex queries
- Create interactive web pages with PHP and MySQL by integrating forms and other HTML features
- Get a thorough grounding in JavaScript, from functions and event handling to accessing the Document Object Model
- Use libraries and packages such as the Smarty web template system, The PEAR program repository and the Yahoo! User Interface Library (YUI)
- Learn how to make Ajax calls and turn your website into a highly dynamic environment
- Find out how to upload and manipulate files and images, validate user input and secure your applications against being hacked
- Develop best practices for error handling and user authentication
Programming tips and exercises in each chapter will help you practice what you’ve learned. If you have a graphics or web design background and know your way around HTML, this book will have you building interactive websites quickly.
If you know HTML, this guide will have you building interactive websites quickly. You’ll learn how to create responsive, data-driven websites with PHP, MySQL, and JavaScript, regardless of whether you already know how to program. Discover how the powerful combination of PHP and MySQL provides an easy way to build modern websites complete with dynamic data and user interaction. You’ll also learn how to add JavaScript to create rich Internet applications and websites.
Learning PHP, MySQL, and JavaScript explains each technology separately, shows you how to combine them, and introduces valuable web programming concepts, including objects, XHTML, cookies, and session management. You’ll practice what you’ve learned with review questions in each chapter, and find a sample social networking platform built with the elements introduced in this book.
This book will help you:
- Understand PHP essentials and the basics of object-oriented programming
- Master MySQL, from database structure to complex queries
- Create web pages with PHP and MySQL by integrating forms and other HTML features
- Learn about JavaScript, from functions and event handling to accessing the Document Object Model
- Use libraries and packages, including the Smarty web template system, PEAR program repository, and the Yahoo! User Interface Library
- Make Ajax calls and turn your website into a highly dynamic environment
- Upload and manipulate files and images, validate user input, and secure your applications
Table of Contents
Preface; Audience; Assumptions This Book Makes; Organization of This Book; Supporting Books; Conventions Used in This Book; Using Code Examples; We’d Like to Hear from You; Safari® Books Online; Acknowledgments; Chapter 1: Introduction to Dynamic Web Content; 1.1 HTTP and HTML: Berners-Lee’s Basics; 1.2 The Benefits of PHP, MySQL, and JavaScript; 1.3 The Apache Web Server; 1.4 About Open Source; 1.5 Bringing It All Together; 1.6 Test Your Knowledge: Questions; Chapter 2: Setting Up a Development Server; 2.1 What Is a WAMP, MAMP, or LAMP?; 2.2 Installing a WAMP on Windows; 2.3 Installing a MAMP on Mac OS X; 2.4 Installing a LAMP on Linux; 2.5 Working Remotely; 2.6 Using a Program Editor; 2.7 Using an IDE; 2.8 Test Your Knowledge: Questions; Chapter 3: Introduction to PHP; 3.1 Incorporating PHP Within HTML; 3.2 This Book’s Examples; 3.3 The Structure of PHP; 3.4 Test Your Knowledge: Questions; Chapter 4: Expressions and Control Flow in PHP; 4.1 Expressions; 4.2 Operators; 4.3 Conditionals; 4.4 Looping; 4.5 Implicit and Explicit Casting; 4.6 PHP Dynamic Linking; 4.7 Test Your Knowledge: Questions; Chapter 5: PHP Functions and Objects; 5.1 PHP Functions; 5.2 Including and Requiring Files; 5.3 PHP Version Compatibility; 5.4 PHP Objects; 5.5 Test Your Knowledge: Questions; Chapter 6: PHP Arrays; 6.1 Basic Access; 6.2 The foreach…as Loop; 6.3 Multidimensional Arrays; 6.4 Using Array Functions; 6.5 Test Your Knowledge: Questions; Chapter 7: Practical PHP; 7.1 Using printf; 7.2 Date and Time Functions; 7.3 File Handling; 7.4 System Calls; 7.5 XHTML; 7.6 Test Your Knowledge: Questions; Chapter 8: Introduction to MySQL; 8.1 MySQL Basics; 8.2 Summary of Database Terms; 8.3 Accessing MySQL via the Command Line; 8.4 Indexes; 8.5 MySQL Functions; 8.6 Accessing MySQL via phpMyAdmin; 8.7 Test Your Knowledge: Questions; Chapter 9: Mastering MySQL; 9.1 Database Design; 9.2 Normalization; 9.3 Relationships; 9.4 Transactions; 9.5 Using EXPLAIN; 9.6 Backing Up and Restoring; 9.7 Test Your Knowledge: Questions; Chapter 10: Accessing MySQL Using PHP; 10.1 Querying a MySQL Database with PHP; 10.2 A Practical Example; 10.3 Practical MySQL; 10.4 Test Your Knowledge: Questions; Chapter 11: Form Handling; 11.1 Building Forms; 11.2 Retrieving Submitted Data; 11.3 An Example Program; 11.4 Test Your Knowledge: Questions; Chapter 12: Templating with Smarty; 12.1 Why Smarty?; 12.2 Installation; 12.3 Creating Scripts; 12.4 Creating Templates; 12.5 A Practical Example; 12.6 Test Your Knowledge: Questions; Chapter 13: Cookies, Sessions, and Authentication; 13.1 Using Cookies in PHP; 13.2 HTTP Authentication; 13.3 Using Sessions; 13.4 Test Your Knowledge: Questions; Chapter 14: Exploring JavaScript; 14.1 JavaScript and HTML Text; 14.2 Using Comments; 14.3 Semicolons; 14.4 Variables; 14.5 Operators; 14.6 Variable Typing; 14.7 Functions; 14.8 Global Variables; 14.9 The Document Object Model; 14.10 Test Your Knowledge: Questions; Chapter 15: Expressions and Control Flow in JavaScript; 15.1 Expressions; 15.2 Operators; 15.3 The with Statement; 15.4 Using onError; 15.5 Using try…catch; 15.6 Conditionals; 15.7 Looping; 15.8 Explicit Casting; 15.9 Test Your Knowledge: Questions; Chapter 16: JavaScript Functions, Objects, and Arrays; 16.1 JavaScript Functions; 16.2 JavaScript Objects; 16.3 JavaScript Arrays; 16.4 Test Your Knowledge: Questions; Chapter 17: JavaScript and PHP Validation and Error Handling; 17.1 Validating User Input with JavaScript; 17.2 Regular Expressions; 17.3 Redisplaying a Form After PHP Validation; 17.4 Test Your Knowledge: Questions; Chapter 18: Using Ajax; 18.1 What Is Ajax?; 18.2 Using XMLHttpRequest; 18.3 Test Your Knowledge: Questions; Chapter 19: Using YUI for Ajax and More; 19.1 Choosing a Framework; 19.2 Using YUI; 19.3 Other Uses for YUI; 19.4 Test Your Knowledge: Questions; Chapter 20: Bringing It All Together; 20.1 Designing a Social Networking Site; 20.2 On the Website; 20.3 rnfunctions.php; 20.4 rnheader.php; 20.5 rnsetup.php; 20.6 index.php; 20.7 rnsignup.php; 20.8 rnsignup.php (YUI version); 20.9 rncheckuser.php; 20.10 rnlogin.php; 20.11 rnprofile.php; 20.12 rnmembers.php; 20.13 rnfriends.php; 20.14 rnmessages.php; 20.15 rnlogout.php; Solutions to the Chapter Questions; Chapter 1 Answers; Chapter 2 Answers; Chapter 3 Answers; Chapter 4 Answers; Chapter 5 Answers; Chapter 6 Answers; Chapter 7 Answers; Chapter 8 Answers; Chapter 9 Answers; Chapter 10 Answers; Chapter 11 Answers; Chapter 12 Answers; Chapter 13 Answers; Chapter 14 Answers; Chapter 15 Answers; Chapter 16 Answers; Chapter 17 Answers; Chapter 18 Answers; Chapter 19 Answers; Online Resources; PHP Resource Sites; MySQL Resource Sites; JavaScript Resource Sites; Ajax Resource Sites; Miscellaneous Resource Sites; O’Reilly Resource Sites; MySQL’s FULLTEXT Stopwords; MySQL Functions; String Functions; Date Functions; Time Functions; Using PEAR and PHPUnit; Installation; Creating a Connect Instance; Rewriting to Use PEAR; Adding Other PEAR Packages; Unit Testing with PHPUnit; Colophon;|
- Preface
- Chapter 1: Introduction to Dynamic Web Content
- Chapter 2: Setting Up a Development Server
- Chapter 3: Introduction to PHP
- Chapter 4: Expressions and Control Flow in PHP
- Chapter 5: PHP Functions and Objects
- Chapter 6: PHP Arrays
- Chapter 7: Practical PHP
- Chapter 8: Introduction to MySQL
- Chapter 9: Mastering MySQL
- Chapter 10: Accessing MySQL Using PHP
- Chapter 11: Form Handling
- Chapter 12: Templating with Smarty
- Chapter 13: Cookies, Sessions, and Authentication
- Chapter 14: Exploring JavaScript
- Chapter 15: Expressions and Control Flow in JavaScript
- Chapter 16: JavaScript Functions, Objects, and Arrays
- Chapter 17: JavaScript and PHP Validation and Error Handling
- Chapter 18: Using Ajax
- Chapter 19: Using YUI for Ajax and More
- Chapter 20: Bringing It All Together
- Solutions to the Chapter Questions
- Online Resources
- MySQL’s FULLTEXT Stopwords
- MySQL Functions
- Using PEAR and PHPUnit
Nixon, R. (2014) Learning PHP, MySQL and JavaScript: With jQuery, CSS & HTML5, Fourth Edition, O’Reilly Media, Inc.
Download Source Code (ZIP 3,153KB)
Companion Web Site: http://lpmj.net/4thedition/
Find out for yourself why Learning PHP, MySQL, & JavaScript 4th Edition is the number-one best-selling blockbuster that has been at the top of the charts for over five years worldwide, is the first result returned on PHP by Amazon US, UK and Canada, the first foreign language title on PHP returned on European Amazon websites, and in the top 10 foreign books on PHP on Amazon Japan and China!
Learning PHP, MySQL, & JavaScript 4th Edition will teach you how to create responsive, data-driven websites with the central technologies of PHP, MySQL, JavaScript, CSS, & HTML5 – whether or not you know how to program. This simple, streamlined guide explains how the powerful combination of PHP and MySQL provides a painless way to build modern websites with dynamic data and user interaction. You’ll also learn how to add JavaScript to create rich Internet websites and applications, and how to use Ajax to handle background communication with a web server.
Build interactive, data-driven websites with the potent combination of open-source technologies and web standards, even if you have only basic HTML knowledge. With this popular hands-on guide, you’ll tackle dynamic web programming with the help of today’s core technologies: PHP, MySQL, JavaScript, jQuery, CSS, and HTML5.
Explore each technology separately, learn how to use them together, and pick up valuable web programming practices along the way. At the end of the book, you’ll put everything together to build a fully functional social networking site, using XAMPP or any development stack you choose.
- Learn PHP in-depth, along with the basics of object-oriented programming
- Explore MySQL, from database structure to complex queries
- Use the MySQLi Extension, PHP’s improved MySQL interface
- Create dynamic PHP web pages that tailor themselves to the user
- Manage cookies and sessions, and maintain a high level of security
- Master the JavaScript language—and enhance it with jQuery
- Use Ajax calls for background browser/server communication
- Acquire CSS2 and CSS3 skills for professionally styling your web pages
- Implement all of the new HTML5 features, including geolocation, audio, video, and the canvas
Contents of the Fourth Edition
(Includes CSS, HTML5, XAMPP, mysqli, & jQuery)
- Introduction to Dynamic Web Content
- Setting Up a Development Server
- Introduction to PHP
- Expressions and Control Flow in PHP
- PHP Functions and Objects
- PHP Arrays
- Practical PHP
- Introduction to MySQL
- Mastering MySQL
- Accessing MySQL Using PHP
- Form Handling
- Cookies, Sessions and Authentication
- Exploring JavaScript
- Expressions and Control Flow in JavaScript
- JavaScript Functions, Objects and Arrays
- JavaScript and PHP Validation and Error Handling
- Using AJAX
- Introduction to CSS
- Advanced CSS with CSS3
- Accessing CSS From JavaScript
- Introduction to jQuery
- Introduction to HTML5
- The HTML5 Canvas
- HTML5 Audio and Video
- Other HTML5 Features
- Bringing it all Together
-
Chapter 1Introduction to Dynamic Web Content
-
HTTP and HTML: Berners-Lee’s Basics
-
The Request/Response Procedure
-
The Benefits of PHP, MySQL, JavaScript, CSS, and HTML5
-
And Then There’s HTML5
-
The Apache Web Server
-
About Open Source
-
Bringing It All Together
-
Questions
-
-
Chapter 2Setting Up a Development Server
-
What Is a WAMP, MAMP, or LAMP?
-
Installing XAMPP on Windows
-
Installing XAMPP on Mac OS X
-
Installing a LAMP on Linux
-
Working Remotely
-
Using a Program Editor
-
Using an IDE
-
Questions
-
-
Chapter 3Introduction to PHP
-
Incorporating PHP Within HTML
-
This Book’s Examples
-
The Structure of PHP
-
Questions
-
-
Chapter 4Expressions and Control Flow in PHP
-
Expressions
-
Operators
-
Conditionals
-
Looping
-
Implicit and Explicit Casting
-
PHP Dynamic Linking
-
Dynamic Linking in Action
-
Questions
-
-
Chapter 5PHP Functions and Objects
-
PHP Functions
-
Including and Requiring Files
-
PHP Version Compatibility
-
PHP Objects
-
Questions
-
-
Chapter 6PHP Arrays
-
Basic Access
-
The foreach…as Loop
-
Multidimensional Arrays
-
Using Array Functions
-
Questions
-
-
Chapter 7Practical PHP
-
Using printf
-
Date and Time Functions
-
File Handling
-
System Calls
-
XHTML or HTML5?
-
Questions
-
-
Chapter 8Introduction to MySQL
-
MySQL Basics
-
Summary of Database Terms
-
Accessing MySQL via the Command Line
-
Indexes
-
MySQL Functions
-
Accessing MySQL via phpMyAdmin
-
Questions
-
-
Chapter 9Mastering MySQL
-
Database Design
-
Normalization
-
Relationships
-
Transactions
-
Using EXPLAIN
-
Backing Up and Restoring
-
Questions
-
-
Chapter 10Accessing MySQL Using PHP
-
Querying a MySQL Database with PHP
-
A Practical Example
-
Practical MySQL
-
Preventing Hacking Attempts
-
Using mysqli Procedurally
-
Questions
-
-
Chapter 11Form Handling
-
Building Forms
-
Retrieving Submitted Data
-
An Example Program
-
What’s New in HTML5?
-
Features Awaiting Full Implementation
-
Questions
-
-
Chapter 12Cookies, Sessions, and Authentication
-
Using Cookies in PHP
-
HTTP Authentication
-
Using Sessions
-
Questions
-
-
Chapter 13Exploring JavaScript
-
JavaScript and HTML Text
-
Using Comments
-
Semicolons
-
Variables
-
Operators
-
Variable Typing
-
Functions
-
Global Variables
-
Local Variables
-
The Document Object Model
-
About document.write
-
Questions
-
-
Chapter 14Expressions and Control Flow in JavaScript
-
Expressions
-
Literals and Variables
-
Operators
-
The with Statement
-
Using onerror
-
Using try…catch
-
Conditionals
-
Looping
-
Explicit Casting
-
Questions
-
-
Chapter 15JavaScript Functions, Objects, and Arrays
-
JavaScript Functions
-
JavaScript Objects
-
JavaScript Arrays
-
Questions
-
-
Chapter 16JavaScript and PHP Validation and Error Handling
-
Validating User Input with JavaScript
-
Regular Expressions
-
Redisplaying a Form After PHP Validation
-
Questions
-
-
Chapter 17Using Ajax
-
What Is Ajax?
-
Using XMLHttpRequest
-
Questions
-
-
Chapter 18Introduction to CSS
-
Importing a Style Sheet
-
Using IDs
-
Using Classes
-
Using Semicolons
-
CSS Rules
-
Style Types
-
CSS Selectors
-
The CSS Cascade
-
Measurements
-
Fonts and Typography
-
Managing Text Styles
-
CSS Colors
-
Positioning Elements
-
Pseudoclasses
-
Shorthand Rules
-
The Box Model and Layout
-
Questions
-
-
Chapter 19Advanced CSS with CSS3
-
Attribute Selectors
-
The box-sizing Property
-
CSS3 Backgrounds
-
Multiple Backgrounds
-
CSS3 Borders
-
Box Shadows
-
Element Overflow
-
Multicolumn Layout
-
Colors and Opacity
-
Text Effects
-
Web Fonts
-
Google Web Fonts
-
Transformations
-
3D Transformations
-
Transitions
-
Questions
-
-
Chapter 20Accessing CSS from JavaScript
-
Revisiting the getElementById Function
-
Accessing CSS Properties from JavaScript
-
Inline JavaScript
-
Adding New Elements
-
Using Interrupts
-
Questions
-
-
Chapter 21Introduction to jQuery
-
Why jQuery?
-
Including jQuery
-
jQuery Syntax
-
Selectors
-
Handling Events
-
Waiting Until the Document Is Ready
-
Event Functions and Properties
-
Special Effects
-
Manipulating the DOM
-
Dynamically Applying Classes
-
Modifying Dimensions
-
DOM Traversal
-
Using jQuery Without Selectors
-
Using Ajax
-
Plug-Ins
-
Questions
-
-
Chapter 22Introduction to HTML5
-
The Canvas
-
Geolocation
-
Audio and Video
-
Forms
-
Local Storage
-
Web Workers
-
Web Applications
-
Microdata
-
Summary
-
Questions
-
-
Chapter 23The HTML5 Canvas
-
Creating and Accessing a Canvas
-
Writing Text to the Canvas
-
Drawing Lines
-
Using Paths
-
Filling Areas
-
The clip Method
-
The isPointInPath Method
-
Working with Curves
-
Manipulating Images
-
Editing at the Pixel Level
-
Advanced Graphical Effects
-
Transformations
-
Summary
-
Questions
-
-
Chapter 24HTML5 Audio and Video
-
About Codecs
-
The <audio> Element
-
Supporting Non-HTML5 Browsers
-
The <video> Element
-
Summary
-
Questions
-
-
Chapter 25Other HTML5 Features
-
Geolocation and the GPS Service
-
Other Location Methods
-
Geolocation and HTML5
-
Local Storage
-
Web Workers
-
Offline Web Applications
-
Drag and Drop
-
Cross-Document Messaging
-
Microdata
-
Other HTML5 Tags
-
Summary
-
Questions
-
-
Chapter 26Bringing It All Together
-
Designing a Social Networking Site
-
On the Website
-
functions.php
-
header.php
-
setup.php
-
index.php
-
signup.php
-
checkuser.php
-
login.php
-
profile.php
-
members.php
-
friends.php
-
messages.php
-
logout.php
-
styles.css
-
javascript.js
-
-
Appendix Solutions to the Chapter Questions
-
Appendix Online Resources
-
Appendix MySQL’s FULLTEXT Stopwords
-
Appendix MySQL Functions
-
Appendix jQuery Selectors, Objects, and Methods
Ullman, L. (2012) PHP and MySQL for Dynamic Web Sites, Fourth Edition, Visual QuickPro Guide, PeachPit Press
Download eBook PDF (PDF 32,316KB)
Download Source Code (ZIP 164KB)
Companion Web Site: http://www.larryullman.com/books/php-and-mysql-for-dynamic-web-sites-visual-quickpro-guide-4th-edition/
See also:
Ullman, L. (2011) A Complete(-ish) Login System Using jQuery
(http://www.peachpit.com/articles/article.aspx?p=1768315)
A login system is a fundamental part of many websites. Requiring only a simple HTML form and a backend script, this feature can readily be improved using Ajax, and is easy enough to do with the jQuery framework. In this article, Larry Ullman explains how to create a complete(-ish) and fully reliable jQuery-enabled login system.
Ullman, L. (2011) Implementing a Search Engine for a Message Board Using PHP and MySQL
(http://www.peachpit.com/articles/article.aspx?p=1802754)
Everyone knows how critical a good search engine is to the success of a website, but most developers—even well-seasoned ones—don’t know how to code a search engine themselves. In this article, Larry Ullman discusses a couple of ways to add a search engine to a site, while providing plenty of real-world code.
Ullman, L. (2011) Mining a User Management System in PHP and MySQL
(http://www.peachpit.com/articles/article.aspx?p=1769256)
Basic user management—registration, logging in, and logging out—is a key aspect of today’s dynamic websites. This article walks you through some of the simple ways you can extend the code to provide added functionality to your website.
———————————————————————————————————————————
It hasn’t taken Web developers long to discover that when it comes to creating dynamic, database-driven Web sites, MySQL and PHP provide a winning open-source combination. Add this book to the mix, and there’s no limit to the powerful, interactive Web sites that developers can create. With step-by-step instructions, complete scripts, and expert tips to guide readers, veteran author and database designer Larry Ullman gets right down to business: After grounding readers with separate discussions of first the scripting language (PHP) and then the database program (MySQL), he goes on to cover security, sessions and cookies, and using additional Web tools, with several sections devoted to creating sample applications. This guide is indispensable for beginning to intermediate level Web designers who want to replace their static sites with something dynamic. In this edition, the bulk of the new material covers the latest features and techniques with PHP and MySQL. Also new to this edition are chapters introducing jQuery and object-oriented programming techniques.
Table of Contents
- Introduction
- Chapter 1: Introduction to PHP
- Basic Syntax
- Sending Data to the Web Browser
- Writing Comments
- What Are Variables?
- Introducing Strings
- Concatenating Strings
- Introducing Numbers
- Introducing Constants
- Single vs. Double Quotation Marks
- Basic Debugging Steps
- Review and Pursue
- Chapter 2: Programming with PHP
- Creating an HTML Form
- Handling an HTML Form
- Conditionals and Operators
- Validating Form Data
- Introducing Arrays
- For and While Loops
- Review and Pursue
- Chapter 3: Creating Dynamic Web Sites
- Including Multiple Files
- Handling HTML Forms, Revisited
- Making Sticky Forms
- Creating Your Own Functions
- Review and Pursue
- Chapter 4: Introduction to MySQL
- Naming Database Elements
- Choosing Your Column Types
- Choosing Other Column Properties
- Accessing MySQL
- Review and Pursue
- Chapter 5: Introduction to SQL
- Creating Databases and Tables
- Inserting Records
- Selecting Data
- Using Conditionals
- Using LIKE and NOT LIKE
- Sorting Query Results
- Limiting Query Results
- Updating Data
- Deleting Data
- Using Functions
- Review and Pursue
- Chapter 6: Database Design
- Normalization
- Creating Indexes
- Using Different Table Types
- Languages and MySQL
- Time Zones and MySQL
- Foreign Key Constraints
- Review and Pursue
- Chapter 7: Advanced SQL and MySQL
- Performing Joins
- Grouping Selected Results
- Advanced Selections
- Performing FULLTEXT Searches
- Optimizing Queries
- Performing Transactions
- Database Encryption
- Review and Pursue
- Chapter 8: Error Handling and Debugging
- Error Types and Basic Debugging
- Displaying PHP Errors
- Adjusting Error Reporting in PHP
- Creating Custom Error Handlers
- PHP Debugging Techniques
- SQL and MySQL Debugging Techniques
- Review and Pursue
- Chapter 9: Using PHP with MySQL
- Modifying the Template
- Connecting to MySQL
- Executing Simple Queries
- Retrieving Query Results
- Ensuring Secure SQL
- Counting Returned Records
- Updating Records with PHP
- Review and Pursue
- Chapter 10: Common Programming Techniques
- Sending Values to a Script
- Using Hidden Form Inputs
- Editing Existing Records
- Paginating Query Results
- Making Sortable Displays
- Review and Pursue
- Chapter 11: Web Application Development
- Sending Email
- Handling File Uploads
- PHP and JavaScript
- Understanding HTTP Headers
- Date and Time Functions
- Review and Pursue
- Chapter 12: Cookies and Sessions
- Making a Login Page
- Defining the Login Functions
- Using Cookies
- Using Sessions
- Improving Session Security
- Review and Pursue
- Chapter 13: Security Methods
- Preventing Spam
- Validating Data by Type
- Validating Files by Type
- Preventing XSS Attacks
- Using the Filter Extension
- Preventing SQL Injection Attacks
- Review and Pursue
- Chapter 14: Perl-compatible Regular Expressions
- Creating a Test Script
- Defining Simple Patterns
- Using Quantifiers
- Using Character Classes
- Finding All Matches
- Using Modifiers
- Matching and Replacing Patterns
- Review and Pursue
- Chapter 15: Introducing jQuery
- What is jQuery?
- Incorporating jQuery
- Using jQuery
- Selecting Page Elements
- Event Handling
- DOM Manipulation
- Using Ajax
- Review and Pursue
- Chapter 16: An OOP Primer
- Fundamentals and Syntax
- Working with MySQL
- The DateTime Class
- Review and Pursue
- Chapter 17: Example—Message Board
- Making the Database
- Writing the Templates
- Creating the Index Page
- Creating the Forum Page
- Creating the Thread Page
- Posting Messages
- Review and Pursue
- Chapter 18: Example—User Registration
- Creating the Templates
- Writing the Configuration Scripts
- Creating the Home Page
- Registration
- Activating an Account
- Logging In and Logging Out
- Password Management
- Review and Pursue
- Chapter 19: Example—E-Commerce
- Creating the Database
- The Administrative Side
- Creating the Public Template
- The Product Catalog
- The Shopping Cart
- Recording the Orders
- Review and Pursue
- Appendix A: Installation(AVAILABLE ONLINE)
- Installation on Windows
- Installation on Mac OS X
- Managing MySQL Users
- Testing Your Installation
- Configuring PHP
- Configuring Apache
Ullman, L. (2011) PHP for the Web Visual QuickPro Guide, Fourth Edition, PeachPit Press
Download eBook PDF (PDF 13,613KB)
Download Source Code (ZIP 84KB)
Companion Web Site: http://www.larryullman.com/books/php-for-the-web-visual-quickstart-guide-4th-edition/
It hasn’t taken Web developers long to discover that when it comes to creating dynamic, database-driven Web sites, MySQL and PHP provide a winning open-source combination. Add this book to the mix, and there’s no limit to the powerful, interactive Web sites that developers can create. With step-by-step instructions, complete scripts, and expert tips to guide readers, veteran author and database designer Larry Ullman gets right down to business: After grounding readers with separate discussions of first the scripting language (PHP) and then the database program (MySQL), he goes on to cover security, sessions and cookies, and using additional Web tools, with several sections devoted to creating sample applications. This guide is indispensable for beginning to intermediate level Web designers who want to replace their static sites with something dynamic. In this edition, the bulk of the new material covers the latest features and techniques with PHP and MySQL. Also new to this edition are chapters introducing jQuery and object-oriented programming techniques.
Table of Contents
Introduction
Chapter 1 Getting Started with PHP
Chapter 2 Variables
Chapter 3 HTML Forms and PHP
Chapter 4 Using Numbers
Chapter 5 Using Strings
Chapter 6 Control Structures
Chapter 7 Using Arrays
Chapter 8 Creating Web Applications
Chapter 9 Cookies and Sessions
Chapter 10 Creating Functions
Chapter 11 Files and Directories
Chapter 12 Intro to Databases
Chapter 13 Putting It All Together
Appendix A Installation and Configuration
Appendix B Resources and Next Steps
Meloni, J. C. (2007 ) Sams Teach Yourself PHP. MySQL and Apache All on One, Third Edition, Sams Publishing
A more recent version of this book is available
Download Source Code – Third Edition (ZIP 78KB)
Download Source Code – Fourth Edition (ZIP 88KB)
In just a short time, you can learn how to use PHP, MySQL, and Apache together to create dynamic, interactive websites and applications using the three leading open-source web development technologies.
Using a straightforward, step-by-step approach, each lesson in this book builds on the previous ones, enabling you to learn the essentials of PHP scripting, MySQL databases, and the Apache web server from the ground up.
Regardless of whether you run Linux, Windows, or Mac OS X, the enclosed CD includes a complete starter kit that lets you install all the software you need to set up a stable environment for learning, testing, and production.
Learn how to…
- Install, configure, and set up the PHP scripting language, the MySQL database system, and the Apache Web server
- Get these technologies to work together to create a dynamic, database-backed website
- Interact with MySQL using PHP
- Work with forms and files
- Create a web-based discussion forum or mailing list
- Add a storefront and shopping cart to your site
- Optimize your MySQL databases
- Fine-tune the Apache server’s performance
- Restrict access to your applications
- Set up a secure web server
CD-ROM Includes
- A complete PHP, MySQL, and Apache starter kit for Windows®, Linux®, or Mac® OS X.
Table of Contents
&n>
Who Should Read This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
How This Book Is Organized. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . 2
About the Book’s Source Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Conventions Used in This Book. . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 3
Part I: Getting Up and Running
1: Installation QuickStart Guide
Linux/UNIX Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Windows Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Mac OS X Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 16
Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 20
2: Installing and Configuring MySQL
Current and Future Versions of MySQL . . . . . . . . . . . . . . .. . . . . . . . . . . . . 21
How to Get MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Installing MySQL on Linux/UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Installing MySQL on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Installing MySQL on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Troubleshooting Your Installation . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . 32
Basic Security Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Introducing the MySQL Privilege System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Working with User Privileges. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3: Installing and Configuring Apache
Current and Future Versions of Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Choosing the Appropriate Installation Method . . . . . . . . . . . . . . . .. . . . . . . . . . . 44
Installing Apache on Linux/UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Installing Apache on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Installing Apache on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . 48
Apache Configuration File Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Apache Log Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Apache-Related Commands . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 57
Starting Apache for the First Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . 60
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4: Installing and Configuring PHP
Current and Future Versions of PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Building PHP on Linux/UNIX with Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Installing PHP on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . 69
Installing PHP on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
php.ini Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Testing Your Installation . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Getting Installation Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
The Basics of PHP Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Part II: PHP Language Structure
5: The Building Blocks of PHP
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Operators and Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
6: Flow Control Functions in PHP
Switching Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Code Blocks and Browser Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
7: Working with Functions
What Is a Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 131
Calling Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Defining a Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Returning Values from User-Defined Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Saving State Between Function Calls with the static Statement . . . . . . . . . . . . . . . . 140
More About Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Testing for the Existence of a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
8: Working with Arrays 149
What Are Arrays? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Creating Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . 150
Some Array-Related Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
9: Working with Objects 159
Creating an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Object Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Part III: Getting Involved with the Code
10: Working with Strings, Dates, and Time
Formatting Strings with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Investigating Strings in PHP . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . 180
Manipulating Strings with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Using Date and Time Functions in PHP. . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 191
Other String, Date, and Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 197
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
11: Working with Forms
Creating a Simple Input Form. . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 201
Accessing Form Input with User-Defined Arrays . . . . . . . . . . . . .. . . . . . . . . . . . . . 203
Combining HTML and PHP Code on a Single Page . . . . . . . . . . . . . . . . 206
Using Hidden Fields to Save State. . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Redirecting the User. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Sending Mail on Form Submission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Working with File Uploads . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 217
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
12: Working with Cookies and User Sessions
Introducing Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Setting a Cookie with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Deleting a Cookie with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . 227
Session Function Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Starting a Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Working with Session Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Passing Session IDs in the Query String . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 233
Destroying Sessions and Unsetting Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Using Sessions in an Environment with Registered Users . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
13: Working with Files and Directories
Including Files with include() . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . 239
Validating Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Creating and Deleting Files. . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Opening a File for Writing, Reading, or Appending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Reading from Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Writing or Appending to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Working with Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Opening Pipes to and from Processes Using popen() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Running Commands with exec() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Running Commands with system() or passthru() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
14: Working with Images
Understanding the Image-Creation Process . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . 269
Necessary Modifications to PHP . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 270
Drawing a New Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Getting Fancy with Pie Charts . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 275
Modifying Existing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Image Creation from User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Using Images Created by Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Part IV: PHP and MySQL Integration
15: Understanding the Database Design Process
The Importance of Good Database Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Types of Table Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Understanding Normalization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Following the Design Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
16: Learning Basic SQL Commands
Learning the MySQL Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
Learning the Table Creation Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Using the INSERT Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Using the SELECT Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Using WHERE in Your Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Selecting from Multiple Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Using the UPDATE Command to Modify Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Using the REPLACE Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Using the DELETE Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Frequently Used String Functions in MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Using Date and Time Functions in MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
17: Using Transactions and Stored Procedures in MySQL
What Are Transactions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
What Are Stored Procedures?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
18: Interacting with MySQL Using PHP
MySQL Versus MySQLi Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Connecting to MySQL with PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Working with MySQL Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Part V: Basic Projects
19: Managing a Simple Mailing List
Developing the Subscription Mechanism. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Developing the Mailing Mechanism. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
20: Creating an Online Address Book
Planning and Creating the Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Creating an Include File for Common Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
Creating a Menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Creating the Record Addition Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Viewing Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Creating the Record Deletion Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Adding Subentries to a Record. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Workshop . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
21: Creating a Simple Discussion Forum
Designing the Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Creating an Include File for Common Functions . . . . . .. . . . . . . . . . . . . . . . . . . . 416
Creating the Input Forms and Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Displaying the Topic List . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Displaying the Posts in a Topic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Adding Posts to a Topic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
22: Creating an Online Storefront
Planning and Creating the Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Displaying Categories of Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Displaying Items. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
23: Creating a Shopping Cart Mechanism
Planning and Creating the Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
Integrating the Cart with Your Storefront . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Payment Methods and the Checkout Sequence. . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . 455
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
24: Creating a Simple Calendar
Building a Simple Display Calendar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Creating a Calendar Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
25: Restricting Access to Your Applications
Authentication Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . 481
Apache Authentication Module Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Using Apache for Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
Combining Apache Access Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Limiting Access Based on HTTP Methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Restricting Access Based on Cookie Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
26: Logging and Monitoring Web Server Activity
Standard Apache Access Logging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
Standard Apache Error Logging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
Managing Apache Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Logging Custom Information to a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
27: Application Localization
About Internationalization and Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
About Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
Environment Modifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
Creating a Localized Page Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
28: Working with XML
What Is XML?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Accessing XML in PHP Using DOM Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Accessing XML in PHP Using SimpleXML Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Part VI: Administration and Fine-Tuning
29: Apache Performance Tuning and Virtual Hosting
Scalability Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
Load Testing with ApacheBench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
Proactive Performance Tuning. . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 549
Preventing Abuse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
Implementing Virtual Hosting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
30: Setting Up a Secure Web Server
The Need for Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
The SSL Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
Obtaining and Installing SSL Tools . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . 567
Managing Certificates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
SSL Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
31: Optimizing and Tuning MySQL
Building an Optimized Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 575
MySQL Startup Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . 577
Optimizing Your Table Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Optimizing Your Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Using the FLUSH Command. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
Using the SHOW Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . 588
Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
32: Software Upgrades
Staying in the Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
Upgrading MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
Upgrading Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
Upgrading PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
Ballard, P. and Moncur, M. (2009) Sams Teach Yourself Ajax, JavaScript and PHP All in One, Sams Publishing
Download eBook PDF (PDF 4,184KB)
Download Video Learning Starter Kit booklet (PDF 7,063KB)
Download Source Code (ZIP 43KB)
In just a short time, you can learn how to use Ajax, JavaScript, and PHP to create interactive interfaces to your web applications by combining these powerful technologies.
No previous Ajax programming experience is required. Using a straightforward, step-by-step approach, each lesson in this book builds on the previous ones, enabling you to learn the essentials of Ajax programming with JavaScript, PHP, and related technologies from the ground up.
Regardless of whether you run Linux, Windows, or Mac OS X, the enclosed CD includes a complete Ajax programming starter kit that gives you all the programming tools, reference information, JavaScript libraries, and server software you need to set up a stable environment for learning, testing, and production.
Learn how to…
- Build better, more interactive interfaces for your web applications
- Make JavaScript, HTML, XML, and PHP work together to create Ajax effects
- Compile an Ajax application
- Create and consume web services with SOAP and REST
- Avoid common errors and troubleshoot programs
- Use popular Ajax libraries to speed up and improve common programming tasks
On the CD
- XAMPP for Windows, Mac OS X, and Linux―an easy-to-install package to set up a PHP- and MySQL-enabled Apache server on your computer
- The jEdit programming editor for Windows, Mac, and Linux
- Prototype, Scriptaculous, Rico, and XOAD―popular JavaScript libraries for creating Ajax applications and effects
- A complete Ajax, HTML, XML, and PHP tutorial reference library in searchable PDF format
- Source code for the examples in the book
Table of Contents
Introduction
Part I: Web Basics Refresher 7
Chapter 1: Workings of the Web 9
A Short History of the Internet………………………………………………….. 9
The World Wide Web…………………………………………………………… 10
Introducing HTTP…………………………………………………………………. 14
The HTTP Request and Response…………………………………………… 15
HTML Forms………………………………………………………………………. 17
Summary…………………………………………………………………………….. 20
chapter 2: Writing and Styling Pages in HTML and CSS 21
Introducing HTML……………………………………………………………….. 21
Elements of an HTML Page……………………………………………………. 23
A More Advanced HTML Page……………………………………………… 27
Some Useful HTML Tags………………………………………………………. 29
Adding Your Own Style………………………………………………………… 30
Defining the Rules…………………………………………………………………. 31
Add a Little class………………………………………………………………….. 31
Applying Styles…………………………………………………………………….. 33
Formatting Text with Styles…………………………………………………….. 35
Adding Lines……………………………………………………………………….. 39
Summary…………………………………………………………………………….. 40
Chapter 3: Anatomy of an Ajax Application 41
The Need for Ajax……………………………………………………………….. 41
Introducing Ajax…………………………………………………………………… 43
The Constituent Parts of Ajax…………………………………………………. 45
Putting It All Together……………………………………………………………. 47
Summary…………………………………………………………………………….. 49
Part II: Introducing Web Scripting with JavaScript 51
chapter 4: Creating Simple Scripts in JavaScript 53
Tools for Scripting………………………………………………………………… 53
Displaying Time with JavaScript………………………………………………. 54
Beginning the Script………………………………………………………………. 55
Adding JavaScript Statements…………………………………………………. 55
Creating Output……………………………………………………………………. 56
Adding the Script to a Web Page…………………………………………….. 57
Testing the Script………………………………………………………………….. 58
JavaScript Syntax Rules…………………………………………………………. 65
Using Comments………………………………………………………………….. 66
Best Practices for JavaScript…………………………………………………… 67
Summary…………………………………………………………………………….. 69
chapter 5: Working with the Document Object Model (DOM) 71
Understanding Objects………………………………………………………….. 71
Understanding the Document Object Model (DOM)…………………… 72
Working with Web Documents……………………………………………….. 74
Accessing Browser History…………………………………………………….. 77
Working with the location Object…………………………………………….. 78
Summary…………………………………………………………………………….. 80
chapter 6: Using Variables, Strings, and Arrays 81
Using Variables……………………………………………………………………. 81
Understanding Expressions and Operators………………………………… 85
Data Types in JavaScript……………………………………………………….. 86
Converting Between Data Types……………………………………………… 88
Using String Objects……………………………………………………………… 89
Working with Substrings………………………………………………………… 92
Using Numeric Arrays…………………………………………………………… 94
Using String Arrays……………………………………………………………….. 96
Sorting a Numeric Array………………………………………………………… 98
Summary…………………………………………………………………………… 101
chapter 7: Using Functions and Objects 103
Using Functions………………………………………………………………….. 103
Introducing Objects…………………………………………………………….. 108
Using Objects to Simplify Scripting………………………………………… 109
Extending Built-in Objects…………………………………………………….. 112
Summary…………………………………………………………………………… 115
chapter 8: Controlling Flow with Conditions and Loops 117
The if Statement………………………………………………………………….. 118
Using Shorthand Conditional Expressions………………………………… 121
Testing Multiple Conditions with if and else………………………………. 122
Using Multiple Conditions with switch…………………………………….. 124
Using for Loops………………………………………………………………….. 125
Using while Loops………………………………………………………………. 128
Using do…while Loops……………………………………………………….. 128
Working with Loops……………………………………………………………. 129
Looping Through Object Properties……………………………………….. 131
Summary…………………………………………………………………………… 134
chapter 9: Using Built-In Functions and Libraries 135
Using the Math Object…………………………………………………………. 135
Working with Math Functions……………………………………………….. 137
Using the with Keyword………………………………………………………. 139
Working with Dates…………………………………………………………….. 140
Using Third-Party Libraries…………………………………………………… 143
Other Libraries…………………………………………………………………… 144
Summary…………………………………………………………………………… 145
Part III: Introducing Ajax 147
chapter 10: The Heart of Ajax–the XMLHTTPRequest Object 149
Introducing XMLHTTPRequest…………………………………………….. 149
Creating the XMLHTTPRequest Object…………………………………. 150
Summary…………………………………………………………………………… 156
chapter 11: Talking with the Server 157
Sending the Server Request………………………………………………….. 157
Monitoring Server Status……………………………………………………… 162
The Callback Function…………………………………………………………. 163
Summary…………………………………………………………………………… 166
chapter 12: Using the Returned Data 167
The responseText and responseXML Properties………………………. 167
Parsing responseXML…………………………………………………………. 171
Providing User Feedback…………………………………………………….. 172
Summary…………………………………………………………………………… 174
Chapter 13: Our First Ajax Application 175
Constructing the Ajax Application………………………………………….. 175
The HTML Document…………………………………………………………. 176
Adding JavaScript………………………………………………………………. 177
Putting It All Together………………………………………………………….. 180
Summary…………………………………………………………………………… 184
Part IV: Server-side Scripting with PHP 185
Chapter 14: Getting to Know PHP 187
PHP Basics……………………………………………………………………….. 187
Your First PHP Script…………………………………………………………. 190
Summary…………………………………………………………………………… 194
chapter 15: Variables 195
Understanding Variables………………………………………………………. 195
Data Types………………………………………………………………………… 197
Working with Numbers………………………………………………………… 198
Numeric Data Types……………………………………………………………. 200
Numeric Functions………………………………………………………………. 200
Working with Strings…………………………………………………………… 202
Formatting Strings……………………………………………………………….. 203
String Functions………………………………………………………………….. 205
Working with Arrays…………………………………………………………… 206
Array Functions………………………………………………………………….. 208
Date Formats…………………………………………………………………….. 209
Working with Timestamps…………………………………………………….. 210
Summary…………………………………………………………………………… 213
Chapter 16: Flow Control 215
Conditional Statements………………………………………………………… 215
Loops………………………………………………………………………………. 220
Summary…………………………………………………………………………… 222
Chapter 17: Functions 223
Using Functions………………………………………………………………….. 223
Arguments and Return Values……………………………………………….. 225
Using Library Files………………………………………………………………. 229
Summary…………………………………………………………………………… 229
Chapter 18: Using Classes 231
Object-Oriented PHP………………………………………………………….. 231
What Is a Class?………………………………………………………………… 232
Creating and Using Objects………………………………………………….. 233
Summary…………………………………………………………………………… 236
Part V: More Complex Ajax Technologies 237
Chapter 19: Returning Data as Text 239
Getting More from the responseText Property………………………….. 239
Summary…………………………………………………………………………… 245
Chapter 20: AHAH–Asynchronous HTML and HTTP 247
Introducing AHAH……………………………………………………………… 247
Creating a Small Library for AHAH……………………………………….. 248
Using myAHAHlib.js…………………………………………………………… 250
Summary…………………………………………………………………………… 255
Chapter 21: Returning Data as XML 257
Adding the “x” to Ajax…………………………………………………………. 257
The responseXML Property…………………………………………………. 258
Project–An RSS Headline Reader……………………………………….. 262
Summary…………………………………………………………………………… 269
chapter 22: Web Services and the REST and SOAP Protocols 271
Introduction to Web Services………………………………………………… 271
REST–Representational State Transfer………………………………….. 272
Using REST in Practice………………………………………………………… 274
Web Services Using SOAP………………………………………………….. 278
The SOAP Protocol……………………………………………………………. 279
Using Ajax and SOAP…………………………………………………………. 282
Reviewing SOAP and REST…………………………………………………. 283
Summary…………………………………………………………………………… 284
chapter 23: A JavaScript Library for Ajax 285
An Ajax Library…………………………………………………………………. 285
Reviewing myAHAHlib.js…………………………………………………….. 286
Implementing Our Library…………………………………………………….. 287
Using the Library………………………………………………………………… 290
Summary…………………………………………………………………………… 293
chapter 24: Ajax Gotchas 295
Common Ajax Errors………………………………………………………….. 295
The Back Button………………………………………………………………… 296
Bookmarking and Links……………………………………………………….. 297
Telling the User That Something Is Happening………………………….. 297
Making Ajax Degrade Elegantly…………………………………………….. 297
Dealing with Search Engine Spiders………………………………………… 298
Pointing Out Active Page Elements…………………………………………. 299
Don’t Use Ajax Where It’s Inappropriate……………………………….. 299
Security…………………………………………………………………………….. 300
Test Code Across Multiple Platforms……………………………………… 300
Ajax Won’t Cure a Bad Design…………………………………………….. 301
Some Programming Gotchas…………………………………………………. 301
Summary…………………………………………………………………………… 302
Part VI: Ajax Tools and Resources 303
Chapter 25: The prototype.js Toolkit 305
Introducing prototype.js……………………………………………………….. 305
Wrapping XMLHTTPRequest–the Ajax Object……………………… 308
Example Project–Stock Price Reader…………………………………… 311
Summary…………………………………………………………………………… 313
chapter 26: Using Rico 315
Introducing Rico…………………………………………………………………. 315
Rico’s Other Interface Tools…………………………………………………. 320
Summary…………………………………………………………………………… 324
Chapter 27: Using Script.aculo.us 325
Downloading the Library………………………………………………………. 325
Including the Files……………………………………………………………….. 326
Using Effects……………………………………………………………………… 326
Building the Script……………………………………………………………….. 327
Summary…………………………………………………………………………… 329
Chapter 28: Using XOAD 331
Introducing XOAD……………………………………………………………… 331
XOAD HTML…………………………………………………………………… 334
Advanced Programming with XOAD……………………………………… 337
Summary…………………………………………………………………………… 338
Appendix: JavaScript, PHP, and Ajax Websites 339
Glossary 343
Zandstra, M. (2004) PHP in 24 Hours, Third Edition, Sams Publishing
Download eBook CHM (ZIP 2,278KB)
Download Source Code(ZIP 108KB)
Think of all the things you could do in 24 hours. Go sightseeing. Read a book. Learn PHP. Sams Teach Yourself PHP in 24 Hours is a unique learning tool that is divided into 24 one-hour lessons over five sections. Starting with the basics, you will discover the fundamentals of PHP and how to apply that knowledge to create dynamic websites with forms, cookies and authentication functions. You will also find out how to access databases, as well as how to integrate system components, e-mail, LDAP, network sockets and more. A support website includes access to source code, PHP updates, errata and links to other relevant websites. Sams Teach Yourself PHP in 24 Hours is a quick and easy way to learn how to create interactive websites for your end user.
Table of Contents
(NOTE: Each chapter concludes with a Summary. Q&A. Workshop. and Exercise.)
Introduction.
I. GETTING STARTED.
Hour 1. PHP: From Home Page to Web Enterprise.
What Is PHP? What Need Does PHP Fulfill? What’s New in PHP 5. The Zend Engine. Why Choose PHP? What’s New in This Edition. Hour 2. Installing PHP.
Platforms, Servers, Databases, and PHP. Where to Find PHP and More. Installing PHP for Linux and Apache. Some configure Options. Configuring Apache. php.ini. Help! Hour 3. A First Script.
Our First Script. Combining HTML and PHP. Adding Comments to PHP Code.II. THE LANGUAGE.
Hour 4. The Building Blocks.
Variables. Data Types. Operators and Expressions. Constants. Hour 5. Going with the Flow.
Switching Flow. Loops. Code Blocks and Browser Output. Hour 6. Functions.
What Is a Function? Calling Functions. Defining a Function. Returning Values from User-Defined Functions. Dynamic Function Calls. Variable Scope. Saving State Between Function Calls with the static Statement. More About Arguments. Creating Anonymous Functions. Testing for Function Existence. Hour 7. Arrays.
What Is an Array? Creating Arrays. Associative Arrays. Multidimensional Arrays. Accessing Arrays. Manipulating Arrays. Sorting Arrays. Functions Revisited. Hour 8. Working with Strings.
Formatting Strings. Investigating Strings. Manipulating Strings. Hour 9. Objects.
What Is an Object? Creating an Object. Object Properties. Object Methods. Limiting Access to Object Properties. Limiting Access to Object Methods. Constraining Arguments to Methods with Hints. Inheritance. Testing Classes and Objects. Automatically Loading Include Files with __autoload(). Storing and Retrieving Objects.III. WORKING WITH PHP.
Hour 10. Working with Forms.
Superglobal Variables. The $_SERVER Array. A Script to Acquire User Input. Importing User Input into Global Scope. Accessing Form Input with User-Defined Arrays. Combining HTML and PHP Code on a Single Page. Using Hidden Fields to Save State. Redirecting the User. File Upload Forms and Scripts. Hour 11. Working with Files.
Including Files with include(). Using include_once() and include_path to Manage Larger Projects. Testing Files. Creating and Deleting Files. Opening a File for Writing, Reading, or Appending. Reading from Files. Reading the Contents of a File with file_get_contents(). Writing or Appending to a File. Writing Data to a File with file_put_contents(). Working with Directories. Hour 12. Working with the DBA Functions.
Beneath the Abstraction. Opening a Database. Adding Data to the Database. Amending Elements in a Database. Reading from a Database. Determining Whether an Item Exists in a Database. Deleting an Item from a Database. Adding Complex Data Structures to a Database. An Example. Hour 13. Database Integration-SQL.
A (Very) Brief Introduction to SQL. Connecting to the MySQL Database Server. Selecting a Database. Finding Out About Errors. Adding Data to a Table. Acquiring the Value of an Automatically Incremented Field. Accessing Information. Changing Data. SQLite: A Lightweight SQL Engine. Selecting Data. Using the PEAR DB Package. Hour 14. Beyond the Box.
Server Variables Revisited. A Brief Summary of an HTTP Client/Server Negotiation. Getting a Document from a Remote Address. Converting IP Addresses and Hostnames. Making a Network Connection. Sending Mail with the mail() Function. An Introduction to Streams. Hour 15. Images On-the-Fly.
Checking Your Configuration with gd_info(). Creating and Outputting Images. Acquiring Color. Drawing Lines. Applying Color Fills. Drawing an Arc. Drawing a Rectangle. Drawing a Polygon. Making a Color Transparent. Working with Text. Bringing It Together. Hour 16. Working with Dates and Times.
Getting the Date with time(). Converting a Timestamp with getdate(). Converting a Timestamp with date(). Creating Timestamps with mktime(). An Example. A Date Pull-down Library. Hour 17. Advanced Objects.
Objects and Constants. Static Properties. Static Methods. Intercepting Calls to Object Properties and Methods. Final Methods. Cleaning Up Using Destructors. Managing Error Conditions with Exceptions. Tools for Building Object Hierarchies. Passing and Assigning Objects. Hour 18. Working with Regular Expressions.
Perl Compatible Regular Expressions. Hour 19. Saving State with Cookies and Query Strings.
Cookies. Setting a Cookie with PHP. Working with the Query String. Creating a Query String. Hour 20. Saving State with Session Functions.
What Are Session Functions? Starting a Session with session_start(). Working with Session Variables. Destroying Sessions and Unsetting Elements. Passing Session IDs in the Query String. Encoding and Decoding Session Variables. Hour 21. Working with the Server Environment.
Opening Pipes to and from Processes with popen() and proc_open(). Running Commands with exec(). Running External Commands with system() or the Backtick Operator. Plugging Security Holes with escapeshellcmd(). Running External Applications with passthru(). Calling an External CGI Script with the virtual() Function. Hour 22. XML.
What Is XML? XML Parser Functions. An Introduction to the DOM XML Functions. XSL: A Brief Discussion. Introducing SimpleXML.IV. EXTENDING PHP.
Hour 23. PEAR: Reusable Components to Extend the Power of PHP.
What Is PEAR? Some PEAR Packages in Action. PEAR and Your Own Code. Hour 24. Toward a Framework for Larger Projects.
Principles and Problems. The Controller Object. The RequestHelper and DataStore Classes. The CommandFactory Class. The Command Class. The Dispatcher Class. Working with the Framework. Where Now, and Was It Worth It? Glossary.
Download Source Code (ZIP 59,111KB)
Assuming no previous experience with PHP or MySQL, this book–and–video package is ideal reading for anyone who wants to go beyond HTML/CSS in order to provide clients with the most dynamic web sites possible. The approachable tone breaks down the basics of programming and PHP and MySQL in individual lessons starting with the installation of the programs necessary to run PHP. You begin with a static web site and then watch and learn as PHP functionality is added as you work through the lessons.
When working with databases, the MySQL database is introduced with demonstrations that show how to interact with it. The accompanying videos enhance your learning experience, as each lesson in the book is portrayed in the video exercises.
Lessons include:
? Getting started with PHP
? Setting up your workspace
? Adding PHP to a web page
? Learning PHP syntax
? Working with variables
? Debugging code
? Working with complex data
? Making decisions
? Repeating program steps
? Learning about scope
? Reusing code with functions
? Creating forms
? Introducing object–oriented programming
? Defining classes
? Using classes
? Using advanced techniques
? Handling errors
? Writing secure code
? Introducing databases
? Introducing MySQL
? Creating and connecting to the
? Creating tables
? Entering data
? Selecting data
? Using multiple tables
? Changing data
? Deleting data
? Preventing database security issues
? Creating user logins
? Turn the case study into a content management system
Table of Contents
INTRODUCTION xvii
SECTION I: GETTING STARTED WITH PHP
LESSON 1: SETTING UP YOUR WORKSPACE 3
LESSON 2: ADDING PHP TO A WEB PAGE 23
LESSON 3: LEARNING PHP SYNTAX 33
LESSON 4: WORKING WITH VARIABLES 45
LESSON 5: DEBUGGING CODE 57
LESSON 6: WORKING WITH COMPLEX DATA 71
SECTION II: WORKING WITH PHP CONTROLS, FUNCTIONS, AND FORMS
LESSON 7: MAKING DECISIONS 91
LESSON 8: REPEATING PROGRAM STEPS 107
LESSON 9: LEARNING ABOUT SCOPE 119
LESSON 10: REUSING CODE WITH FUNCTIONS 125
LESSON 11: CREATING FORMS 141
SECTION III: OBJECTS AND CLASSES
LESSON 12: INTRODUCING OBJECT–ORIENTED PROGRAMMING 161
LESSON 13: DEFINING CLASSES 167
LESSON 14: USING CLASSES 177
LESSON 15: USING ADVANCED TECHNIQUES 187
SECTION IV: PREVENTING PROBLEMS
LESSON 16: HANDLING ERRORS 205
LESSON 17: WRITING SECURE CODE 217
SECTION V: USING A DATABASE
LESSON 18: INTRODUCING DATABASES 227
LESSON 19: INTRODUCING MYSQL 239
LESSON 20: CREATING AND CONNECTING TO THE DATABASE 263
LESSON 21: CREATING TABLES 275
LESSON 22: ENTERING DATA 295
LESSON 23: SELECTING DATA 313
LESSON 24: USING MULTIPLE TABLES 331
LESSON 25: CHANGING DATA 343
LESSON 26: DELETING DATA 361
LESSON 27: PREVENTING DATABASE SECURITY ISSUES 387
SECTION VI: PUTTING IT ALL TOGETHER
LESSON 28: CREATING USER LOGINS 399
LESSON 29: TURN THE CASE STUDY INTO A CONTENT MANAGEMENT SYSTEM 419
LESSON 30: CREATING A DYNAMIC MENU 443
LESSON 31: NEXT STEPS 461
APPENDIX : WHAT’S ON THE DVD? 463
INDEX 467
Hopkins, C. (2013) JUMP START – PHP, SitePoint Pty. Ltd
Download eBook PDF (PDF 3,024KB)
Download Source Code (ZIP 661KB)
PHP is a key server-side technology in web development, enabling you to quickly and simply develop interactive, usable and engaging websites and applications.
In just one weekend with this SitePoint book, you’ll learn how to:
- Install all of the software you need to begin developing PHP applications
- Understand PHP functions and syntax
- Build a complete, working PHP application from scratch: a simple social networking app
Plus you’ll discover how to use modern techniques such as MVC and REST
Get up to speed with PHP in a weekend.
PHP is a hugely popular language that powers the backend of 80% of websites, including Internet giants such as Facebook, Wikipedia and WordPress. It’s an easy language to learn and great for beginners, so you can get up and running fast!
In Jump Start PHP you’ll learn step-by-step how to build a complete blog application, understand how PHP works with data, and improve the security of your PHP apps. In just one weekend, you’ll have a solid base to start writing PHP on your own!
Contents
- Server Kick-Start
- PHP & Data
- Objects and OOP
- Forms
- Sessions and Cookies
- PHP and Security
McGrath, M. (2004) PHP 5 in Easy Steps, Computer Step
Download Source Code (ZIP KB)
PHP 5 in easy steps instructs how to create exciting interactive web pages using the latest major release of the popular PHP scripting language. PHP allows data to be easily exchanged between a web browser and a web server – both on the Windows platform and on Unix-based platforms, such as Linux. Exciting chapters, with complete code examples, illustrate the major features of the PHP language and screenshots depict the actual output from each example script. You are also introduced to MySQL databases and shown, by example, how PHP can interact with databases to store user input, and to retrieve stored data for delivery to a web browser as components of a web page.
“PHP 5 in easy steps” begins by explaining how to download and install the free Apache web server, the free MySQL database server, and the free PHP 5 interpreter. This allows you to establish an environment in which to run PHP scripts on your own computer. Examples show how PHP scripts can generate dynamic content, manipulate files, store user-data, send email, authenticate log-in attempts and communicate with databases. This book makes no assumption of previous knowledge of any programming or scripting language so it’s ideal for the newcomer to PHP. Each chapter builds your knowledge of PHP scripting. By the end of this book you will have gained a sound understanding of the PHP language and be able to write your own scripts that can be run on any web server that is configured for PHP.
“PHP 5 in easy steps” has an easy-to-follow style that will appeal to anyone who wants to add PHP scripts to their web pages. It will appeal to web developers wanting to add dynamic interaction to their web sites. It will appeal to the programmer who quickly wants to add server-side scripting to their skills set. It will appeal to the hobbyist who wants to begin creating PHP scripts for upload to their own ISP. It will appeal to the student, and to those seeking a career in computing, who need a fundamental understanding of server-side scripting in PHP.
Shiflett, C. (2006) Essential PHP Security, O’Reilly Media, Inc
Download eBook CHM (CHM 355KB)
Being highly flexible in building dynamic, database-driven web applications makes the PHP programming language one of the most popular web development tools in use today. It also works beautifully with other open source tools, such as the MySQL database and the Apache web server. However, as more web sites are developed in PHP, they become targets for malicious attackers, and developers need to prepare for the attacks.
Security is an issue that demands attention, given the growing frequency of attacks on web sites. Essential PHP Security explains the most common types of attacks and how to write code that isn’t susceptible to them. By examining specific attacks and the techniques used to protect against them, you will have a deeper understanding and appreciation of the safeguards you are about to learn in this book.
In the much-needed (and highly-requested) Essential PHP Security, each chapter covers an aspect of a web application (such as form processing, database programming, session management, and authentication). Chapters describe potential attacks with examples and then explain techniques to help you prevent those attacks.
Topics covered include:
- Preventing cross-site scripting (XSS) vulnerabilities
- Protecting against SQL injection attacks
- Complicating session hijacking attempts
You are in good hands with author Chris Shiflett, an internationally-recognized expert in the field of PHP security. Shiflett is also the founder and President of Brain Bulb, a PHP consultancy that offers a variety of services to clients around the world.
Table of Contents
Foreword; Preface; What’s Inside; Style Conventions; Comments and Questions; Safari Enabled; Acknowledgments; Chapter 1: Introduction; 1.1 PHP Features; 1.2 Principles; 1.3 Practices; Chapter 2: Forms and URLs; 2.1 Forms and Data; 2.2 Semantic URL Attacks; 2.3 File Upload Attacks; 2.4 Cross-Site Scripting; 2.5 Cross-Site Request Forgeries; 2.6 Spoofed Form Submissions; 2.7 Spoofed HTTP Requests; Chapter 3: Databases and SQL; 3.1 Exposed Access Credentials; 3.2 SQL Injection; 3.3 Exposed Data; Chapter 4: Sessions and Cookies; 4.1 Cookie Theft; 4.2 Exposed Session Data; 4.3 Session Fixation; 4.4 Session Hijacking; Chapter 5: Includes; 5.1 Exposed Source Code; 5.2 Backdoor URLs; 5.3 Filename Manipulation; 5.4 Code Injection; Chapter 6: Files and Commands; 6.1 Traversing the Filesystem; 6.2 Remote File Risks; 6.3 Command Injection; Chapter 7: Authentication and Authorization; 7.1 Brute Force Attacks; 7.2 Password Sniffing; 7.3 Replay Attacks; 7.4 Persistent Logins; Chapter 8: Shared Hosting; 8.1 Exposed Source Code; 8.2 Exposed Session Data; 8.3 Session Injection; 8.4 Filesystem Browsing; 8.5 Safe Mode; Appendix A: Configuration Directives; A.1 allow_url_fopen; A.2 disable_functions; A.3 display_errors; A.4 enable_dl; A.5 error_reporting; A.6 file_uploads; A.7 log_errors; A.8 magic_quotes_gpc; A.9 memory_limit; A.10 open_basedir; A.11 register_globals; A.12 safe_mode; Appendix B: Functions; B.1 eval(); B.2 exec(); B.3 file(); B.4 file_get_contents(); B.5 fopen(); B.6 include; B.7 passthru(); B.8 phpinfo(); B.9 popen(); B.10 preg_replace(); B.11 proc_open(); B.12 readfile(); B.13 require; B.14 shell_exec(); B.15 system(); Appendix C: Cryptography; C.1 Storing Passwords; C.2 Using mcrypt; C.3 Storing Credit Card Numbers; C.4 Encrypting Session Data; About the Author; Colophon;|
- Foreword
- Preface
- Chapter 1: Introduction
- Chapter 2: Forms and URLs
- Chapter 3: Databases and SQL
- Chapter 4: Sessions and Cookies
- Chapter 5: Includes
- Chapter 6: Files and Commands
- Chapter 7: Authentication and Authorization
- Chapter 8: Shared Hosting
- Appendix A: Configuration Directives
- Appendix B: Functions
- Appendix C: Cryptography
Brinzarea-Iamandi, B., Darie, C. and Hendrix, A. (2009) AJAX and PHP: Building Modern Web Applications – Building User-Friendly Web 2.0 Applications with JavaScript and PHP, Second Edition, Packt Publishing
Download eBook PDF (PDF 4,613KB)
Download Source Code (ZIP 550KB)
This book is a step-by-step, example-driven AJAX tutorial, featuring complete case studies. Each chapter contains a friendly mix of theory and practice, so that your journey through the book will be pleasant, yet efficient. You’ll be coding your first AJAX application at the end of the first chapter, and with each new chapter you’ll develop increasingly complex AJAX applications featuring advanced techniques and coding patterns.AJAX and PHP: Building Modern Web Applications, 2nd Edition, is written for PHP developers who: Want to learn how to use PHP, JavaScript, MySQL and jQuery to implement Web 2.0 applications, Are looking for a step-by-step, example-driven AJAX tutorial, Want to learn advanced AJAX coding patterns and techniques and be able to assess the security and SEO implications of their code
AJAX enables interactive interfaces that can replace traditional user interfaces. Enhance the user experience of your PHP website using AJAX with this practical and friendly tutorial! This book is the most efficient resource you can get to enter the exciting world of AJAX with PHP. Based on numerous examples and detailed case studies, this AJAX with PHP tutorial will build your foundation knowledge for creating faster, better web applications.
Detailed description
The best AJAX tutorial for PHP developers has been completely rewritten to be your friendly guide to modern Web 2.0 development techniques! AJAX and PHP: Building Modern Web Applications, 2nd Edition covers every significant aspect of creating and maintaining AJAX and PHP applications.
This book will teach you how to use PHP, JavaScript, MySQL and jQuery to build modern, responsive web applications. After building a strong foundation, the book will walk you through numerous real-world case studies covering techniques you’ll be likely to need for your own applications:
- Learn how to write unobtrusive, degradable, portable, SEO-friendly AJAX code
- Understand the object-oriented model of JavaScript and JSON
- Learn how to use the jQuery JavaScript library by going through two complete case studies
- Debug your AJAX and PHP code using modern tools
- Assess the security implications of writing AJAX code and avoid security risks such as cross-site scripting
- Learn advanced AJAX and PHP patterns and techniques such as predictive fetching, progress indicator, graceful degradation, cross-domain calls, and more
- Understand the complete client-server mechanism by going through complete, step-by-step case studies, including AJAX Form Validation, and AJAX Online Chat and AJAX Editable DataGrid with jQuery
What You Will Learn
- Create faster, lighter, better web applications by using the AJAX technologies to their full potential
- Learn to use PHP and MySQL on the server, and Javascript and jQuery on the client, to build real-world AJAX applications
- Combine client-side and server-side functionality to enhance the user experience of your site using AJAX
- Learn to simulate private, instance, and static class members in JavaScript
- Build an AJAX-enabled form validation page, which is safe to work even if the client doesn’t support JavaScript and AJAX
Table of Contents
Yank, Kevin (2009) Build Your Own Database Driven Web Site Using PHP and MySQL, Fourth Edition, SitePoint Pty. Ltd
There is a more recent edition of this book
Download eBook PDF (PDF 7,519KB)
Download Source Code (ZIP 127KB)
Build Your own Database Driven Web Site Using PHP & MySQL is a practical hands-on guide to learning all the tools, principles and techniques needed to build a fully functional database-driven web site using PHP & MySQL.
This book covers everything from installing PHP & MySQL under Windows, Linux, and Mac through to building a live web-based content management system.
While this is essentially a beginners book, it also covers more advanced topics such as the storage of binary data in MySQL, and cookies and sessions in PHP. It comes complete with a set of handy reference guides for PHP & MySQL that include:
- MySQL syntax
- MySQL functions
- MysQL column types
- PHP functions for working with MySQL
In this book, I’ll provide you with a hands-on look at what’s involved in building a database driven web site using PHP and MySQL. If your web host provides PHP and MySQL support, you’re in great shape. If not, I’ll show you how to install them on Windows, Mac OS X, and Linux computers, so don’t sweat it.
This book is your map to the twisty path that every beginner must navigate to learn PHP and MySQL today. Grab your favorite walking stick; let’s go hiking!
Contents
- Installation
- Introducing MySQL
- Introducing PHP
- Publishing MySQL Data on the Web
- Relational Database Design
- Structured PHP Programming
- A Content Management System
- Content Formatting with Regular Expressions
- Cookies, Sessions, and Access Control
- MySQL Administration
- Advanced SQL Queries
- Binary Data
Yank, Kevin (2012) PHP and MySQL Novice to Ninja, Fifth Edition, SitePoint Pty, Ltd.
There is a more recent edition of this book
Download eBook PDF (PDF 18,142KB)
Download Source Code (ZIP 204KB)
PHP & MySQL: Novice to Ninja is a practical hands-on guide to learning all the tools, principles and techniques needed to build a fully-functional database-driven web site using PHP & MySQL.
This book covers everything from installing PHP & MySQL under Windows, Linux, and Mac through to building a live web-based content management system.
While this is essentially a beginner’s book, it also covers more advanced topics such as the storage of binary data in MySQL, and cookies and sessions in PHP. It comes complete with a set of handy reference guides for PHP & MySQL that include:
- MySQL syntax
- MySQL functions
- MysQL column types
- PHP functions for working with MySQL
What will I learn?
- In-depth Tutorials: Easy-to-follow tutorials with downloadable code examples.
- Best-practice PHP Coding: Learn rock-solid PHP programming principles from the start.
- Hassle-free Setup Instructions: Get yourself up and running on OS X, Windows, and Linux with ease.
- Fun Example Project: Put your knowledge to work building a working CMS: your own online joke database.
- Object Oriented Programming (OOP): Keep your PHP manageable and flexible using OOP principles.
- Add a Shopping Cart: Develop a working ecommerce platform from scratch.
Who should read this book?
PHP & MySQL: Novice to Ninja, 5th Edition is a 500+ page book aimed at web designers looking to make the leap into server-side programming. You’ll be expected to be comfortable with simple HTML, although no knowledge of Cascading Style Sheets (CSS) or JavaScript is required.
By the end of this book, you’ll have a grasp of what’s involved in building a database driven website. If you follow the examples, you’ll also learn the basics of PHP (a server-side scripting language that gives you easy access to a database, and a lot more) and Structured Query Language (SQL—the standard language for interacting with relational databases) as supported by MySQL, the most popular free database engine available today. Most importantly, you’ll come away with everything you need to start on your very own database driven site!
What’s new in the fifth edition?
- Up-to-date: updated for Windows 7, Mac OS X Lion, and the latest versions of PHP, MySQL, and phpMyAdmin.
- Now even easier to get started: using all-in-one installation packages like XAMPP and MAMP.
- No command prompt required: phpMyAdmin is used for all database administration tasks, and for sending SQL commands to MySQL.
- Best practice database code: this edition uses the robust and portable PHP Data Objects (PDO) API and prepared statements to work with MySQL.
- HTML5 markup: easy-to-read HTML5 markup that all the cool kids are using these days.
Sklar, D. (2004) Learning PHP5, O’Reilly Media, Inc.
There is a newer version of this book
Download eBook PDF (PDF 1,469KB)
Download Source Code (ZIP 160KB)
PHP has gained a following among non-technical web designers who need to add interactive aspects to their sites. Offering a gentle learning curve, PHP is an accessible yet powerful language for creating dynamic web pages. As its popularity has grown, PHP’s basic feature set has become increasingly more sophisticated. Now PHP 5 boasts advanced features–such as new object-oriented capabilities and support for XML and Web Services–that will please even the most experienced web professionals while still remaining user-friendly enough for those with a lower tolerance for technical jargon.If you’ve wanted to try your hand at PHP but haven’t known where to start, then Learning PHP 5 is the book you need. If you’ve wanted to try your hand at PHP but haven’t known where to start, then Learning PHP 5 is the book you need. With attention to both PHP 4 and the new PHP version 5, it provides everything from a explanation of how PHP works with your web server and web browser to the ins and outs of working with databases and HTML forms. Written by the co-author of the popular PHP Cookbook, this book is for intelligent (but not necessarily highly-technical) readers. Learning PHP 5 guides you through every aspect of the language you’ll need to master for professional web programming results. This book provides a hands-on learning experience complete with exercises to make sure the lessons stick.Learning PHP 5 covers the following topics, and more:
- How PHP works with your web browser and web server
- PHP language basics, including data, variables, logic and looping
- Working with arrays and functions
- Making web forms
- Working with databases like MySQL
- Remembering users with sessions
- Parsing and generating XML
- Debugging
Written by David Sklar, coauthor of the PHP Cookbook and an instructor in PHP, this book offers the ideal classroom learning experience whether you’re in a classroom or on your own. From learning how to install PHP to designing database-backed web applications, Learning PHP 5 will guide you through every aspect of the language you’ll need to master to achieve professional web programming results.
Table of Contents
Dedication; Preface; Who This Book Is For; Contents of This Book; Other Resources; Conventions Used in This Book; Using Code Examples; Comments and Questions; Acknowledgments; Chapter 1: Orientation and First Steps; 1.1 PHP’s Place in the Web World; 1.2 What’s So Great About PHP?; 1.3 PHP in Action; 1.4 Basic Rules of PHP Programs; 1.5 Chapter Summary; Chapter 2: Working with Text and Numbers; 2.1 Text; 2.2 Numbers; 2.3 Variables; 2.4 Chapter Summary; 2.5 Exercises; Chapter 3: Making Decisions and Repeating Yourself; 3.1 Understanding true and false; 3.2 Making Decisions; 3.3 Building Complicated Decisions; 3.4 Repeating Yourself; 3.5 Chapter Summary; 3.6 Exercises; Chapter 4: Working with Arrays; 4.1 Array Basics; 4.2 Looping Through Arrays; 4.3 Modifying Arrays; 4.4 Sorting Arrays; 4.5 Using Multidimensional Arrays; 4.6 Chapter Summary; 4.7 Exercises; Chapter 5: Functions; 5.1 Declaring and Calling Functions; 5.2 Passing Arguments to Functions; 5.3 Returning Values from Functions; 5.4 Understanding Variable Scope; 5.5 Chapter Summary; 5.6 Exercises; Chapter 6: Making Web Forms; 6.1 Useful Server Variables; 6.2 Accessing Form Parameters; 6.3 Form Processing with Functions; 6.4 Validating Data; 6.5 Displaying Default Values; 6.6 Putting It All Together; 6.7 Chapter Summary; 6.8 Exercises; Chapter 7: Storing Information with Databases; 7.1 Organizing Data in a Database; 7.2 Connecting to a Database Program; 7.3 Creating a Table; 7.4 Putting Data into the Database; 7.5 Inserting Form Data Safely; 7.6 Generating Unique IDs; 7.7 A Complete Data Insertion Form; 7.8 Retrieving Data from the Database; 7.9 Changing the Format of Retrieved Rows; 7.10 Retrieving Form Data Safely; 7.11 A Complete Data Retrieval Form; 7.12 MySQL Without PEAR DB; 7.13 Chapter Summary; 7.14 Exercises; Chapter 8: Remembering Users with Cookies and Sessions; 8.1 Working with Cookies; 8.2 Activating Sessions; 8.3 Storing and Retrieving Information; 8.4 Configuring Sessions; 8.5 Login and User Identification; 8.6 Why setcookie( ) and session_start( ) Want to Be at the Top of the Page; 8.7 Chapter Summary; 8.8 Exercises; Chapter 9: Handling Dates and Times; 9.1 Displaying the Date or Time; 9.2 Parsing a Date or Time; 9.3 Dates and Times in Forms; 9.4 Displaying a Calendar; 9.5 Chapter Summary; 9.6 Exercises; Chapter 10: Working with Files; 10.1 Understanding File Permissions; 10.2 Reading and Writing Entire Files; 10.3 Reading and Writing Parts of Files; 10.4 Working with CSV Files; 10.5 Inspecting File Permissions; 10.6 Checking for Errors; 10.7 Sanitizing Externally Supplied Filenames; 10.8 Chapter Summary; 10.9 Exercises; Chapter 11: Parsing and Generating XML; 11.1 Parsing an XML Document; 11.2 Generating an XML Document; 11.3 Chapter Summary; 11.4 Exercises; Chapter 12: Debugging; 12.1 Controlling Where Errors Appear; 12.2 Fixing Parse Errors; 12.3 Inspecting Program Data; 12.4 Fixing Database Errors; 12.5 Chapter Summary; 12.6 Exercises; Chapter 13: What Else Can You Do with PHP?; 13.1 Graphics; 13.2 PDF; 13.3 Shockwave/Flash; 13.4 Browser-Specific Code; 13.5 Sending and Receiving Mail; 13.6 Uploading Files in Forms; 13.7 The HTML_QuickForm Form-Handling Framework; 13.8 Classes and Objects; 13.9 Advanced XML Processing; 13.10 SQLite; 13.11 Running Shell Commands; 13.12 Advanced Math; 13.13 Encryption; 13.14 Talking to Other Languages; 13.15 IMAP, POP3, and NNTP; 13.16 Command-Line PHP; 13.17 PHP-GTK; 13.18 Even More Things You Can Do with PHP; Appendix A: Installing and Configuring the PHP Interpreter; A.1 Using PHP with a Web-Hosting Provider; A.2 Installing the PHP Interpreter; A.3 Installing PEAR; A.4 Downloading and Installing PHP’s Friends; A.5 Modifying PHP Configuration Directives; A.6 Appendix Summary; Appendix B: Regular Expression Basics; B.1 Characters and Metacharacters; B.2 Quantifiers; B.3 Anchors; B.4 Character Classes; B.5 Greed; B.6 PHP’s PCRE Functions; B.7 Appendix Summary; B.8 Exercises; Appendix C: Answers To Exercises; C.1 Chapter 2; C.2 Chapter 3; C.3 Chapter 4; C.4 Chapter 5; C.5 Chapter 6; C.6 Chapter 7; C.7 Chapter 8; C.8 Chapter 9; C.9 Chapter 10; C.10 Chapter 11; C.11 Chapter 12; C.12 Appendix B; Colophon;|
- Dedication
- Preface
- Chapter 1: Orientation and First Steps
- Chapter 2: Working with Text and Numbers
- Chapter 3: Making Decisions and Repeating Yourself
- Chapter 4: Working with Arrays
- Chapter 5: Functions
- Chapter 6: Making Web Forms
- Chapter 7: Storing Information with Databases
- Chapter 8: Remembering Users with Cookies and Sessions
- Chapter 9: Handling Dates and Times
- Chapter 10: Working with Files
- Chapter 11: Parsing and Generating XML
- Chapter 12: Debugging
- Chapter 13: What Else Can You Do with PHP?
- Appendix A: Installing and Configuring the PHP Interpreter
- Appendix B: Regular Expression Basics
- Appendix C: Answers To Exercises
Valade, J. (2007) PHP and MySQL For Dummies, Third Edition, Wiley Publishing, Inc.
Download eBook PDF (PDF 7,179KB)
Download Source Code (ZIP 52KB)
Here′s what Web designers need to know to create dynamic, database–driven Web sites
To be on the cutting edge, Web sites need to serve up HTML, CSS, and products specific to the needs of different customers using different browsers. An effective e–commerce site gathers information about users and provides information they need to get the desired result.
PHP scripting language with a MySQL back–end database offers an effective way to design sites that meet these requirements. This full updated 4th Edition of PHP & MySQL For Dummies gets you quickly up to speed, even if your experience is limited.
- Explains the easy way to install and set up PHP and MySQL using XAMPP, so it works the same on Linux, Mac, and Windows
- Shows you how to secure files on a Web host and how to write secure code
- Packed with useful and understandable code examples for Web site creators who are not professional programmers
- Fully updated to ensure your code will be compliant based on PHP 5.3 and MySQL 5.1.31
- Provides clear, accurate code examples
PHP & MySQL For Dummies, 4th Edition provides what you need to know to create sites that get results.
Table of Contents
Introduction.
Part I: Developing a Web Database Application Using PHP and MySQL.
Chapter 1: Introduction to PHP and MySQL.
Chapter 2: Setting Up Your Work Environment.
Chapter 3: Developing a Web Database Application.
Part II: MySQL Database.
Chapter 4: Building the Database.
Chapter 5: Protecting Your Data.
Part III: PHP.
Chapter 6: General PHP.
Chapter 7: PHP Building Blocks for Programs.
Chapter 8: Data In, Data Out.
Chapter 9: Moving Information from One Web Page to the Next.
Part IV: Applications.
Chapter 10: Putting It All Together.
Chapter 11: Building an Online Catalog.
Chapter 12: Building a Members Only Web Site.
Part V: The Part of Tens.
Chapter 13: Ten Things You Might Want to Do Using PHP Functions.
Chapter 14: Ten PHP Gotchas.
Part VI: Appendixes.
Appendix A: Installing PHP, MySQL, and Apache from XAMPP.
Appendix B: Configuring PHP.