Dear Reader, PHP for Absolute Beginners will take you from zero to full-speed with PHP programming in an easy-to-understand, practical manner. Rather than building applications with no real-world use, this book teaches you PHP by walking you through the development of a blogging web site. You’ll start by creating a simple web-ready blog, then you'll learn how to add password-protected controls, support for multiple pages, the ability to upload and resize images, a user comment system, and finally, how to integrate with sites like Twitter. Along the way, you'll also learn a few advanced tricks including creating friendly URLs with .htaccess, using regular expressions, object-oriented programming, and more. I wrote this book to help you make the leap to PHP developer in hopes that you can put your valuable skills to work for your company, your clients, or on your own personal blog. The concepts in this book will leave you ready to take on the challenges of the new online world, all while having fun! Jason Lengstorf
THE APRESS ROADMAP
Companion eBook
PHP for Absolute Beginners
PHP Objects, Patterns, and Practice
Beginning PHP and MySQL
Practical Web 2.0 Applications with PHP
Pro PHP: Patterns, Frameworks, Testing, and More
Beginning Ajax and PHP
See last page for details on $10 eBook version
www.apress.com
)3".
US $34.99
Lengstorf
SOURCE CODE ONLINE
Companion eBook Available
PHP for Absolute Beginners
PHP for Absolute Beginners
The Expert’s Voice® in Open Source
PHP
for Absolute Beginners Everything you need to know to get started with PHP
Jason Lengstorf
Shelve in: PHP User level: Beginner
this print for content only—size & color not accurate
For my dad, who showed me that nothing stands between a bear and its honey.
iii
Download at WoweBook.Com
Contents at a Glance ■About the Author ....................................................................................................... xiv ■About the Technical Reviewer.................................................................................... xv ■Acknowledgments..................................................................................................... xvi ■Introduction.............................................................................................................. xvii ■Chapter 1: Setting Up the PHP Development Environment...........................................3 ■Chapter 2: Understanding PHP: Language Basics ......................................................29 ■Chapter 3: Passing Information with PHP..................................................................69 ■Chapter 4: Working with Databases...........................................................................97 ■Chapter 5: Building the Entry Manager ....................................................................125 ■Chapter 6: Adding Support for Multiple Pages.........................................................157 ■Chapter 7: Updating and Deleting Entries ................................................................187 ■Chapter 8: Adding the Ability to Upload Images ......................................................207 ■Chapter 9: Syndicating the Blog...............................................................................263 ■Chapter 10: Adding a Commenting System to Your Blog ........................................283 ■Chapter 11: Adding Password Protection to Administrative Links ..........................311 ■Chapter 12: Finishing Touches.................................................................................341 ■Index .......................................................................................................................369
iv
Download at WoweBook.Com
Contents ■About the Author ....................................................................................................... xiv ■About the Technical Reviewer.................................................................................... xv ■Acknowledgments..................................................................................................... xvi ■Introduction.............................................................................................................. xvii ■Chapter 1: Setting Up the PHP Development Environment...........................................3 Why You Need Apache, MySQL, and PHP................................................................................3 Drilling Down on PHP........................................................................................................3 Stable/Production vs. Development Releases ............................................................4 How PHP Works ..........................................................................................................4 Server-Side vs. Client-Side Scripting .........................................................................4 What Apache Does......................................................................................................5 Store Info with MySQL ......................................................................................................5 Installing PHP, Apache, and MySQL (the Hard Way)................................................................6 Installation Made Easy......................................................................................................6 Installing XAMPP...............................................................................................................6 Step 1: Download XAMPP ...........................................................................................7 Step 2: Open the Installer and Follow the Instructions...............................................7 Step 3: Test XAMPP to Ensure Proper Installation ....................................................11 Choosing a Development Kit .................................................................................................15 Benefiting from SDKs and IDEs.......................................................................................15 Choosing the Right SDK..................................................................................................18 The Eclipse Foundation and PDT ..............................................................................18 Installing and Using the Eclipse PDT .....................................................................................18 Step 1: Downloading the PDT .........................................................................................19 Step 2: Unpacking the PDT Archive ................................................................................19 Step 3: Choosing Your Project Workspace .....................................................................20 Step 4: Creating Your First Project .................................................................................23
v
Download at WoweBook.Com
■ CONTENTS
Step 5: Creating a File ....................................................................................................26 Step 6: Writing Your First Script .....................................................................................27 Summary...............................................................................................................................28 ■Chapter 2: Understanding PHP: Language Basics ......................................................29 Embedding PHP Scripts.........................................................................................................29 Alternative Delimiters .....................................................................................................30 Short Tags ................................................................................................................31 HTML Another option provided to Front Page users was Microsoft’s ASP-style delimiters: <% echo 'This is some text'; %>