Introduction

I'm especially amazed at how the Internet has grown and evolved over the past decade or so. It has grown from a collection of static text documents connected by a few hyperlinks to a platform for delivering rich, distributed applications. And when it comes time to develop these web-based applications, many programmers are choosing PHP and MySQL.

In this book, I present basic code for 12 PHP-powered projects that you can use and extend however you wish. I have tried to write them so the code can be easily reused in future applications, but in some instances the entire application can be reused as well!

I've enjoyed the opportunity to write and share with you this information and I hope you have just as much fun reading it and learning from it. More importantly, I hope you find good, practical uses for the projects found within this book.

Who This Book Is For

I present basic yet functional projects for you to implement and extend in any way you see fit. That very fact assumes you know the fundamentals of programming in PHP and general web development. This book is not a textbook. Still, you do not need to be an advanced PHP programmer to gain much by reading it. New programmers should find this book helpful as it will give them guidance in how to program different applications. The 12 projects may even serve to ignite their curiosity and spur them to write 12 more projects of their own. Intermediate and more experienced programmers will find this book helpful because they are able to take the projects I present, modify them and apply them to their real-world needs.

Some projects build upon previous projects, so while you don't have to read the book from cover to cover, I do suggest reading all relevant chapters (or at least the pertinent sections) regardless of your skill level. For example, in Chapter 7, I present an online photo album, but pictures are uploaded using the AJAX file manager presented in Chapter 6. Both projects are laid out in the manner presented in Chapter 1.

What This Book Covers

The code in this book was written for MySQL 5.0 Community Server and PHP version 5.2.5, so essentially I am covering those releases or greater. Additional modification may be necessary if you plan on using earlier releases.

How This Book Is Structured

Each chapter is organized so following projects can build upon earlier projects. Here's a brief rundown of what you can look forward to in the following chapters:

Chapter 1: User Registration

Create a basic user registration system

Reusable components: configuration/include files, 401.php, User class

Chapter 2: Community Forum

Expand on user registration system to create a community forum with user privileges and threaded posts

Reusable components: JpegThumbnail class, BBCode class

Chapter 3: Mailing List

Create a mailing list with control address and digest mailings

Reusable components: POP3Client class

Chapter 4: Search Engine

Build a custom search engine for your own site

Reusable components: entire application

Chapter 5: Personal Calendar

Write a personal calendar utility to keep yourself organized

Reusable components: entire application

Chapter 6: AJAX File Manager

Create an AJAX-ified file upload and directory viewer

Reusable components: entire application (this project introduces AJAX which will be used in subsequent projects)

Chapter 7: Online Photo Album

Create a file-based image gallery with automatically generated thumbnails that supports JPEG and QuickTime formats.

Reusable components: MovThumbnail class

Chapter 8: Shopping Cart

Write a categorized shopping cart

Reusable components: ShoppingCart class

Chapter 9: Web Site Statistics

Log site traffic and collect information about site visitors to make better business decisions

Reusable components: PieChart class, BarChart class

Chapter 10: News/Blog system

Build a news or blog system with comments and RSS feed

Reusable components: entire application (project also introduces reusable components such as YUI calendar and TinyMCE rich text control)

Chapter 11: Shell Scripts

Write and run management scripts

Reusable components: CommandLine class, recurs_copy() function

Chapter 12: Security and Logging

Learn about SQL injection, path traversal, weak authentication, and XSS and how to avoid them

Reusable components: write_log() function, view_log.php, record delete script

What You Need to Use This Book

Since you'll be writing PHP code, you'll need an editor to do so. Whichever you choose to use is a matter of preference. Additionally, you will also need a server running PHP and MySQL to host your applications and a web browser to access them. What you use is a matter of choice. I've provided instructions for setting up applications on both Unix and Windows platforms when necessary, for example the Mailing List application in Chapter 3, which runs as a scheduled job.

Personally, I used vi to write code, hosted the projects on a server running Slackware Linux and accessed them from a Windows XP computer using Firefox.

Some of the projects make use of special extensions to PHP, although I have tried to keep this to a minimum. For example, the Search Engine application presented in Chapter 4 uses the pspell extension. If additional functionality was needed which could only be provided by an extension, I avoided third-party extensions so that if you want to install a particular extension you only need to look as far as the official documentation at www.php.net. The relevant extensions are mentioned in the appropriate chapters.

Conventions

To help you get the most from the text and keep track of what's happening, I've used a number of conventions throughout the book.

As for styles in the text:

  • We highlight new terms and important words when we introduce them.

  • We show keyboard strokes like this: Ctrl+A.

  • We show file names, URLs, and code within the text like so: persistence.properties.

  • We present code in two different ways:

    We use a monofont type with no highlighting for most code examples.
    We use gray highlighting to emphasize code that's particularly important
    in the present context.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. When at the site, simply locate the book's title (either by using the Search box or by using one of the title lists) and click the Download Code link on the book's detail page to obtain all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-0-470-19242-9.

Once you download the code, just decompress it with your favorite compression tool. Alternately, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book's errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don't spot "your" error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.

  2. Read the terms of use and click Agree.

  3. Complete the required information to join as well as any optional information you wish to provide and click Submit.

  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

You can read messages in the forums without joining P2P but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.200.78