INTRODUCTION
xvi
Introduction
When the first edition of PHP Solutions was published, I was concerned that the subtitle, Dynamic Web
Design Made Easy, sounded overambitious. PHP is not difficult, but nor is it like an instant cake mix: just
add water and stir. Every website is different, so its impossible to grab a script, paste it into a web page,
and expect it to work. My aim was to help web designers with little or no knowledge of programming gain
the confidence to dive into the code and adjust it to their own requirements.
The enduring popularity of the first edition suggests that many readers took up the challenge. Part of the
books success stemmed from the use of clear, straightforward language, highlighting points where you
might make mistakes, with advice on how to solve problems. Another factor was its emphasis on forward
and backward compatibility. The solutions were based on PHP 5, but alternatives were provided for
readers still stuck on PHP 4.
Time has moved on. PHP 5 is now a mature and stable platform. This new edition of PHP Solutions
requires PHP 5.2 and MySQL 4.1 or later. Some code will work with earlier versions, but most of it wont.
The emphasis on future compatibility remains unchanged. All the code in this book avoids features
destined for removal when work resumes on PHP 6 (at the time of this writing, its not known when that will
be).
The decision to drop support for older versions of PHP and MySQL has been liberating. When friends of
ED asked me to prepare a new edition of this book, I initially thought it would involve just brushing away a
few cobwebs. As soon as I started reviewing the code, I realized just how much the need to cater for PHP
4 had constrained me. Its also fair to say that my coding style and knowledge of PHP had expanded
greatly in the intervening years.
As a result, this new edition is a major rewrite. The basic structure of the book remains the same, but
every chapter has been thoroughly revised, and an extra two have been added. In some cases, little
remains of the original chapter other than the title. For example, the file upload and thumbnail creation
scripts in Chapters 6 and 8 have been completely refactored as PHP 5 custom classes, and the mail
processing script in Chapter 5 has been rewritten to make it easier to redeploy in different websites. Other
big changes include a class to check password strength in Chapter 9 and detailed coverage of the date
and time classes introduced in PHP 5.2 and 5.3. Want to display the date of events on the second
Tuesday of each month? Chapter 14 shows how to do it in half a dozen lines of code. Chapter 16 adds
coverage of foreign key constraints in InnoDB, the default storage engine in MySQL 5.5.
I hesitated before devoting so much attention to using PHP classes. Many regard them as an advanced
subject, not suitable for readers who dont have a programming background. But the advantages far
outweighed my reservations. In simple terms, a class is a collection of predefined functions designed to
perform related tasks. The beauty of using classes is that theyre project-neutral. Admittedly, the file
upload class in Chapter 6 is longer than the equivalent script in the first edition of PHP Solutions, but you
can reuse it in multiple projects with just a few lines of code. If youre in hurry or are daunted by the
prospect of building class definitions, you can simply use the finished files. However, I encourage you to
explore the class definitions. The code will teach you a lot of PHP that youll find useful in other situations.