How This Book Is Organized


The book is divided into several chapters, organized by subject:


Chapter 1, Installation and Basics

This chapter walks you through the basics of installing PHP and MySQL, as well as using the excellent PEAR library.


Chapter 2, Web Design

In this chapter, we cover how to use HTML tricks in conjunction with PHP to jazz up your interface.


Chapter 3, DHTML

In this chapter, we use the powerful combination of HTML, CSS, and JavaScript known as Dynamic HTML (DHTML) in conjunction with PHP to show just what you can do in a web browser.


Chapter 4, Graphics

This chapter shows a wide variety of methods that you can use to display data in a graphical form.


Chapter 5, Databases and XML

Databases are critical to PHP applications. In this chapter, we show you how to make flexible database objects and even to build your database layer automatically using code generation.


Chapter 6, Application Design

In this chapter, we take the coverage up a notch and discuss techniques that you can use to develop applications quickly and reliably.


Chapter 7, Patterns

C++, C#, and Java programmers have used design patterns for years. Can you use them in PHP as well? You betcha. This chapter shows how to use several of the design patterns from the original Design Patterns book (Addison Wesley) to make better PHP applications.


Chapter 8, Testing

Do you stay awake at night thinking about whether your PHP application is still running? This chapter covers testing techniques that will find bugs for you and continuously monitor the operation of your site.


Chapter 9, Alternative UIs

In this chapter, we show the use of different user interfaces to work with your PHP code. You can run PHP applications on the desktop, from your cell phone, and from your instant messaging application.


Chapter 10, Fun Stuff

In this chapter, we let it all hang out and use the fun stuff on the Web to monitor multiplayer games, use Google Maps in our applications, and much more.

Common Problems

I often see several problems with PHP applications, and this book helps address a number of these:


Bad database design

Most PHP applications work with a relational database, usually MySQL. Database design is not something that comes easily to most engineers trained in traditional programming languages. The first step in cleaning up an application is to make sure the database design is good [Hack #34].


Poor database use

PHP has provided several different variations on how to access databases, and doing this poorly can cause serious security problems. Fixing the database access layer can start with migrating to PEAR DB or PDO [Hack #35]. After that, you can see if it's possible to generate the SQL [Hack #41], the SELECT code [Hack #42], or the CRUD code [Hack #37].


Code embedded in the page

The next problem I see a lot is code that's embedded directly in the page. In particular, access to the database is embedded right in the code of the page. The code-generating hacks that build SELECT code [Hack #42] and CRUD code [Hack #37] show proper two-tier design with PHP. The SQL dynamic object hack [Hack #36] can also help factor SQL access code off the page.


Processing during the page build

Another issue I see is applications that attempt to do a lot of processing in the web server during the page fetch. An example is when an application needs to send out a lot of email in response to some user action. Often this is done in the page that responds to the user actionwhich leaves the user waiting for a page to come back while the system is sending out a bunch of mail. A message queue [Hack #50] is one elegant solution to this problem.


No testing

I hardly ever see test code in the applications that I look at, but automated testing is the first and best way to feel comfortable about going home at night, especially when your job is writing a 24/7 web application. This book contains information on unit tests [Hack #79] and how to generate them automatically [Hack #80]. It also contains code for checking the site through robots [Hack #83] and through the automation of Internet Explorer [Hack #82], which can even check your JavaScript code.


Provide better user security

Most people use the same password on most or all of their accounts. If your application stores passwords in the clear and your application is compromised, you are giving your users' passwords to the world. Use MD5 to scramble people's passwords [Hack #59]. And use a roles system [Hack #58] to make sure users don't see things they shouldn't see.


Make better use of patterns

I admit that the term design patterns has been overplayed. But there is a lot of good stuff there that has been underutilized in PHP applications. All of Chapter 7 is dedicated to showing how you can use design patterns pragmatically and effectively to make better PHP applications.

These are just a few ideas about how to upgrade your existing web application to something that is reliable and secure. But how about cool?

Making a Cool Web Application

You can do so much in browsers and with browser plug-ins, DHTML, and Ajax that it's not hard to have an application that is cool, is easy to use, and has cutting-edge features. Here are some ideas taken from various parts of the book:


Work from the desktop

Believe it or not, you can use PHP to make desktop applications [Hack #87] so that the same business logic code that runs on your web server can be used right on the desktop. Better yet, this code is portable between Mac OS X, Windows, and Linux, with little (and often no) code rewrite.


Use maps

Mapping has become really popular lately. There are two easy ways to handle mapping with PHP: first with MapServer [Hack #86] and second with Google Maps [Hack #95].


Graph it dynamically

Graphics and graphing are always popular, and there are so many ways to do graphing in PHP. You can use basic HTML [Hack #8], SVG [Hack #28], Dynamic HTML [Hack #22], and the GD library [Hack #31]. I've also included information on how to build an object-oriented layer on top of the graphics library [Hack #29].


Work with your users' applications

Another way to create a more compelling application is to reach out to your users. RSS [Hack #88] has become a very popular way to do that. I even take RSS to your PlayStation Portable [Hack #90]. And you can use more traditional routes like email [Hack #10]. I've also included some information on how to generate Word RTF documents [Hack #48] and Excel spreadsheets [Hack #49], as well as how to take Word [Hack #47] or Excel documents [Hack #45] as input.


Upgrade your web interface

I also include some ideas for generating dynamic menus [Hack #17] and easily creating breadcrumb trails [Hack #4], tabs [Hack #6], skinnable interfaces [Hack #3], pop ups [Hack #12], stickies [Hack #16], drag-and-drop interfaces [Hack #13], calendars [Hack #25], link graphs [Hack #24], and more that will make your web interface the best it can be.

These are just a few ideas from the pages of this book. Dig right in and find out ways to take your PHP to the cutting edge.



PHP Hacks
PHP Hacks: Tips & Tools For Creating Dynamic Websites
ISBN: 0596101392
EAN: 2147483647
Year: 2006
Pages: 163

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net