Home > Store

Sams Teach Yourself PHP, MySQL and Apache All in One, 5th Edition

Register your product to gain access to bonus material or receive a coupon.

Sams Teach Yourself PHP, MySQL and Apache All in One, 5th Edition

eBook (Watermarked)

  • Your Price: $25.59
  • List Price: $31.99
  • Includes EPUB, MOBI, and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    MOBI MOBI The eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

Description

  • Copyright 2012
  • Dimensions: 7" x 9-1/8"
  • Edition: 5th
  • eBook (Watermarked)
  • ISBN-10: 0-13-273183-5
  • ISBN-13: 978-0-13-273183-6

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.

Julie C. Meloni is a technical consultant who has been developing web-based applications since the Web first saw the light of day. She has authored numerous books and articles on web application development and HTML/CSS, and you can find translations of her work in 18 different languages.

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.

Sample Content

Table of Contents

   Introduction 1

PART I: Getting Up and Running

CHAPTER 1: Installation QuickStart Guide with XAMPP 5

   Using Third-Party Installation Packages . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . 5

   Installing XAMPP on Linux/UNIX . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 6

   Installing XAMPP on Windows . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 8

   Installing XAMPP on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

   Securing XAMPP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

   Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

CHAPTER 2: Installing and Configuring MySQL 15

   Current and Future Versions of MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

   How to Get MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . 16

   Installing MySQL on Linux/UNIX . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 16

   Installing MySQL on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . 18

   Installing MySQL on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

   Troubleshooting Your Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

   Basic Security Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . 27

   Introducing the MySQL Privilege System. . . . . . . . . . . . .  . . . . . . . . . . . . . . 28

   Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . . . . . . 34

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

CHAPTER 3: Installing and Configuring Apache 37

   Current and Future Versions of Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

   Choosing the Appropriate Installation Method . . . . . . . . . . . . . . . . . . . . 38

   Installing Apache on Linux/UNIX . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 39

   Installing Apache on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

   Installing Apache on Windows . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 42

   Apache Configuration File Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

   Apache Log Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . . 50

   Apache-Related Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

   Starting Apache for the First Time . . . . . . . . . . . . . . .  . . . . . . . . 53

   Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

   Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

CHAPTER 4: Installing and Configuring PHP 59

   Current and Future Versions of PHP . . . . . . . . . . . . . . . . . . . .  . . . . . . . . 59

   Building PHP on Linux/UNIX with Apache . . . . . . . . . . . . . . . . . . . . . . . . . 60

   Installing PHP on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

   Installing PHP on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

   php.ini Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

   Testing Your Installation . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . 65

   Getting Installation Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

   The Basics of PHP Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

   Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . 73

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 73

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 74

PART II: PHP Language Structure

CHAPTER 5: The Building Blocks of PHP 75

   Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

   Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

   Operators and Expressions . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 85

   Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 94

   Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . 96

CHAPTER 6: Flow Control Functions in PHP 99

   Switching Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . 99

   Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 105

   Code Blocks and Browser Output . . . . . . . . . . . . . . . . . . . . . . . . . 114

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . 116

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . 116

CHAPTER 7: Working with Functions 119

   What Is a Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

   Calling Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . 120

   Defining a Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 121

   Returning Values from User-Defined Functions. . . . . . . . . . . . . . . . 124

   Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 125

   Saving State Between Function Calls with the static Statement . . . . . . . . . . . . . . . . . . 128

   More About Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . 130

   Testing for the Existence of a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . 136

CHAPTER 8: Working with Arrays 139

   What Are Arrays? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

   Creating Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . 140

   Some Array-Related Constructs and Functions . . . . . . . . . . . . . . .. . . . . . . . . . 144

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . 147

CHAPTER 9: Working with Objects 149

   Creating an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

   Object Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 155

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . 157

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . 157

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 157

PART III: Getting Involved with the Code

CHAPTER 10: Working with Strings, Dates, and Time 159

   Formatting Strings with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

   Investigating Strings in PHP . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . 169

   Manipulating Strings with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . 173

   Using Date and Time Functions in PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . 179

   Other String, Date, and Time Functions . . . . . . . . . . . . . . . . . .  . . . . . . 186

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . 186

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

CHAPTER 11: Working with Forms 189

   Creating a Simple Input Form. . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . 189

   Accessing Form Input with User-Defined Arrays . . . . . . . . . .. . . . . . . . . 191

   Combining HTML and PHP Code on a Single Page . . . . . . . . . . . . . . 194

   Using Hidden Fields to Save State. . . . . . . . . . . . . . . . . . . .. . . . . . 197

   Redirecting the User. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

   Sending Mail on Form Submission . . . . . . . . . . . . . . . . .. . . . . . . . . . 200

   Creating the Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 201

   Creating the Script to Send the Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

   Working with File Uploads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 210

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . 211

CHAPTER 12: Working with Cookies and User Sessions 213

   Introducing Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 213

   Setting a Cookie with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

   Deleting a Cookie with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

   Session Function Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . 217

   Starting a Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

   Working with Session Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

   Destroying Sessions and Unsetting Variables . . . . . . . . . . . . . . . . . .. . . . . . . . 223

   Using Sessions in an Environment with Registered Users . . . . . .  . . . . . . 224

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . 225

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 226

CHAPTER 13: Working with Files and Directories 229

   Including Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

   Using include_once . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233

   Validating Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

   Creating and Deleting Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 238

   Opening a File for Writing, Reading, or Appending . . . . . . . . . . . . . . . . . . . . . . . 238

   Reading from Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

   Writing or Appending to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

   Working with Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248

   Opening Pipes to and from Processes Using popen() . . . . . . . . . . .. . . . . . . 251

   Running Commands with exec() . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . 254

   Running Commands with system() or passthru() . . . . . . . . . . . . .. . . . . . 255

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . 258

CHAPTER 14: Working with Images 261

   Understanding the Image-Creation Process . . . . . . . . . . . . . . . . . .  . . . . . . . . . 261

   Necessary Modifications to PHP . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . 262

   Drawing a New Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . 263

   Modifying Existing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271

   Image Creation from User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273

   Using Images Created by Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . . 280

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . 281

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

PART IV: PHP and MySQL Integration

CHAPTER 15: Understanding the Database Design Process 283

   The Importance of Good Database Design . . . . . . . . . . . . . . . . . .  . . . . . . . 283

   Types of Table Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

   Understanding Normalization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289

   Following the Design Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . 294

CHAPTER 16: Learning Basic SQL Commands 297

   Learning the MySQL Data Types . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 298

   Learning the Table-Creation Syntax . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . 301

   Using the INSERT Command. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302

   Using the SELECT Command. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304

   Using WHERE in Your Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . 308

   Selecting from Multiple Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . 310

   Using the UPDATE Command to Modify Records . . . . . . . . . . . . . . . . . . 316

   Using the REPLACE Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 319

   Using the DELETE Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . 320

   Frequently Used String Functions in MySQL. . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 322

   Using Date and Time Functions in MySQL . . . . . . . . . . . . . . . . . . . . . . .  . . . 331

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . 343

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . 346

CHAPTER 17: Using Transactions and Stored Procedures in MySQL 349

   What Are Transactions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349

   What Are Stored Procedures?. . . . . . . . . . . . . . . . . . . . . . . . . .. 353

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356

CHAPTER 18: Interacting with MySQL Using PHP 357

   MySQL or MySQLi Functions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . 357

   Connecting to MySQL with PHP. . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . 358

   Working with MySQL Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . 370

PART V: Basic Projects

CHAPTER 19: Managing a Simple Mailing List 373

   Developing the Subscription Mechanism. . . . . . . . . . . . . . . . . . . . . . . . . . 374

   Developing the Mailing Mechanism. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 385

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385

CHAPTER 20: Creating an Online Address Book 387

   Planning and Creating the Database Tables . . . . . . . . . . . . . . . . . . . . . .. . . . 387

   Creating an Include File for Common Functions . . . . . . . . . . . . . . . . . . . . 390

   Creating a Menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391

   Creating the Record-Addition Mechanism . . . . . . . . . . . . . . . . . . . . . . .. . . . . . 392

   Viewing Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398

   Creating the Record-Deletion Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . 404

   Adding Subentries to a Record. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . 406

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . 414

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414

CHAPTER 21: Creating a Simple Discussion Forum 417

   Designing the Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

   Creating an Include File for Common Functions . . . . . . . . . . . . . . .. . . . . . . 418

   Creating the Input Forms and Scripts . . . . . . . . . . . . . . . . . . . . . .  . . . . . . 419

   Displaying the Topic List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . 423

   Displaying the Posts in a Topic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426

   Adding Posts to a Topic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 433

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . 434

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 434

CHAPTER 22: Creating an Online Storefront 437

   Planning and Creating the Database Tables . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . 437

   Displaying Categories of Items . . . . . . . . . . . . . . . . . . . . . . . 441

   Displaying Items. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . 445

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . 448

CHAPTER 23: Creating a Shopping Cart Mechanism 451

   Planning and Creating the Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451

   Integrating the Cart with Your Storefront . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 453

   Payment Methods and the Checkout Sequence. . . . . . . . . . . . . . . . . .  . . . . . . . 462

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465

CHAPTER 24: Creating a Simple Calendar 467

   Building a Simple Display Calendar. . . . . . . . . . . . . . . . . . . . . . . . . . . 467

   Creating a Calendar Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . 483

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . 489

CHAPTER 25: Restricting Access to Your Applications 491

   Authentication Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491

   Apache Authentication Module Functionality . . . . . . . . . . . . . . . . . . . . . . . . 493

   Using Apache for Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497

   Combining Apache Access Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500

   Limiting Access Based on HTTP Methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501

   Restricting Access Based on Cookie Values. . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 501

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . 507

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . 508

CHAPTER 26: Logging and Monitoring Web Server Activity 509

   Standard Apache Access Logging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509

   Standard Apache Error Logging. . . . . . . . . . . . . . . . . . . . . . . . . . .. . . 515

   Managing Apache Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517

   Logging Custom Information to a Database . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 519

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . 524

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524

CHAPTER 27: Application Localization 527

   About Internationalization and Localization . . . . . . . . . . . . . . .. . . . . 527

   About Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 528

   Environment Modifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529

   Creating a Localized Page Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531

   Localizing Your Application with gettext(). . . . . . . . . . . . . . . . . .  . . . . . . . 536

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538

CHAPTER 28: Working with XML and JSON 541

   What Is XML?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 541

   Accessing XML in PHP Using DOM Functions . . . . . . . . . . . .  . . . . . . . . . . . . . . 544

   Accessing XML in PHP Using SimpleXML Functions . . . . . . . . . . . . . . . . . . . 546

   Working with JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 549

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 554

PART VI: Administration and Fine-Tuning

CHAPTER 29: Apache Performance Tuning and Virtual Hosting 555

   Performance and Scalability Issues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . 555

   Load Testing with ApacheBench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559

   Proactive Performance Tuning. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561

   Preventing Abuse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . 563

   Implementing Virtual Hosting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . 569

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . 571

CHAPTER 30: Setting Up a Secure Web Server 573

   The Need for Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 573

   The SSL Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574

   Obtaining and Installing SSL Tools . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . 579

   Managing Certificates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 582

   SSL Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . 586

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . 586

CHAPTER 31: Optimizing and Tuning MySQL 589

   Building an Optimized Platform . . . . . . . . . . . . . . . . . . . . . . . . .. . 589

   Benchmarking Your Database Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590

   MySQL Startup Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591

   Optimizing Your Table Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593

   Optimizing Your Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . 594

   Using the FLUSH Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . . . . . 595

   Using the SHOW Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . 596

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603

   Q&A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604

CHAPTER 32: Performing Software Upgrades 605

   Staying in the Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . 605

   Upgrading MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607

   Upgrading Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608

   Upgrading PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610

CHAPTER 33: Using Application Frameworks 611

   Understanding Application Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611

   Using the MVC Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . 612

   Installing and Using PHP Application Frameworks . . . . . . . . . . . . . . . . . 614

   Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 617

   Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . . 617

   Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . . . . . . . . . 618

TOC, 9780672335433, 5/2/2012

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020