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.
The Missing Credits......Page 9
Introduction......Page 13
Part One: PHP and MySQL Basics......Page 25
PHP Comes in Two Flavors: Local and Remote......Page 27
PHP: Going Local......Page 33
Write Your First Program......Page 50
Run Your First Program......Page 52
But Where’s That Web Server?......Page 54
Chapter2: PHP Meets HTML......Page 57
Script or HTML?......Page 58
PHP Talks Back......Page 63
Run PHP Scripts Remotely......Page 66
Chapter 3: PHP Syntax: Weird and Wonderful......Page 73
Get Information from a Web Form......Page 74
Working with Text in PHP......Page 81
The $_REQUEST Variable Is an Array......Page 95
What Do You Do with User Information?......Page 102
What Is a Database?......Page 103
Installing MySQL......Page 107
SQL Is a Language for Talking to Databases......Page 116
Part Two: Dynamic Web Pages......Page 129
Chapter 5: Connecting PHP to MySQL......Page 131
Writing a Simple PHP Connection Script......Page 132
Cleaning Up Your Code with Multiple Files......Page 144
Building a Basic SQL Query Runner......Page 150
Chapter 6: Regular Expressions......Page 167
String Matching, Double-Time......Page 168
Chapter 7: Generating Dynamic Web Pages......Page 185
Revisiting a User’s Information......Page 186
Planning Your Database Tables......Page 187
Saving a User’s Information......Page 194
Show Me the User......Page 202
Revisiting (and Redirecting) the Create User Script......Page 220
Part Three: From Web Pages to Web Applications......Page 231
Chapter 8: When Things Go Wrong (and They Will)......Page 233
Planning Your Error Pages......Page 235
Finding a Middle Ground for Error Pages with PHP......Page 241
Add Debugging to Your Application......Page 249
Redirecting On Error......Page 254
Chapter 9: Handling Images and Complexity......Page 265
Images Are Just Files......Page 266
Images Are for Viewing......Page 291
And Now for Something Completely Different......Page 300
Chapter 10: Binary Objects and Image Loading......Page 301
Storing Different Objects in Different Tables......Page 302
Inserting a Raw Image into a Table......Page 304
Your Binary Data Isn’t Safe to Insert...Yet......Page 308
Connecting Users and Images......Page 315
Show Me the Image!......Page 325
Embedding an Image Is Just Viewing an Image......Page 336
So, Which Approach Is Best?......Page 342
Chapter 11: Listing, Iterating, and Administrating......Page 345
Thinking about What You Need as an Admin......Page 346
Listing All Your Users......Page 349
Deleting a User......Page 357
Talking Back to Your Users......Page 363
Standardizing on Messaging......Page 374
Integrating Utilities, Views, and Messages......Page 381
Part Four: Security and the Real World......Page 395
Chapter 12: Authentication and Authorization......Page 397
Basic Authentication......Page 398
Abstracting What’s the Same......Page 407
Passwords Don’t Belong in PHP Scripts......Page 411
Passwords Create Security, But Should Be Secure......Page 425
Chapter 13: Cookies, Sign-Ins, and Ditching Crummy Pop-Ups......Page 431
Moving Beyond Basic Authentication......Page 432
Logging In with Cookies......Page 438
Adding Context-Specific Menus......Page 455
Modeling Groups in Your Database......Page 467
Checking for Group Membership......Page 473
Group-Specific Menus......Page 483
Entering Browser Sessions......Page 487
Memory Lane: Remember That Phishing Problem?......Page 498
Why Would You Ever Use Cookies?......Page 501
Part Five: Appendixes......Page 503
Appendix A: Installing PHP on Windows Without WAMP......Page 505
Appendix B: Installing MySQL Without MAMP or WAMP......Page 511
Index......Page 525