Book Image

AJAX and PHP: Building Responsive Web Applications

By : Mihai Bucica, Cristian Darie, Bogdan Brinzarea, Filip Chereches-Tosa, Philippe Wauthier
Book Image

AJAX and PHP: Building Responsive Web Applications

By: Mihai Bucica, Cristian Darie, Bogdan Brinzarea, Filip Chereches-Tosa, Philippe Wauthier

Overview of this book

Assuming a basic knowledge of PHP, XML, JavaScript and MySQL, this book will help you understand how the heart of AJAX beats and how the constituent technologies work together. After teaching the foundations, the book will walk you through numerous real-world case studies covering tasks you'll be likely to need for your own applications: Server-enabled form-validation page Online chat collaboration tool Customized type-ahead text entry solution Real-time charting using SVG Database-enabled, editable and customizable data grid RSS aggregator application A server-managed sortable list with drag&drop support using the JavaScript toolkit The appendices guide you through installing your working environment, using powerful tools that enable debugging, improving, and profiling your code, working with XSLT and XPath. From the Author, Cristian Darie AJAX and PHP: Building Responsive Web Applications is mainly a book for beginners, but when designing its contents we tried to find the ideal blend of topics that would help both novice and experienced web developers make a big step forward. One customer was very kind to let us know, through a review, that we succeeded: "The theory behind all the technologies used is very clearly explained, without boring you with details about obvious things. Right from the first chapter you start learning by examples. The examples can be easily adapted to many web projects and they cover stuff that is both useful and fun." Here are a few examples of such "useful and fun" things that you can find in this book: details on using proxy scripts to work around the security measures in modern browsers client-side and server-side code that doesn't break when fed with special characters (such as <, ", etc) code that works efficiently with Internet Explorer 5, 6 and 7, Firefox, Opera, Safari, and others a very quick introduction to SVG, the new rebel kid of the web (and of the house) client-server communication based on message queues that guarantee that your messages aren't lost on the way, and arrive in the intended order at the destination server-side state management techniques that use query string parameters and database records to keep track of your client's activity simple yet effective error-handling structures that combine JavaScript code and PHP code to report when something bad happens on the client or on the server a live errata page that is updated as soon as anyone reports a suggestion or a correction a friendly AJAX tutorial and many case studies that teach you how to use JavaScript, PHP, MySQL and XML together in order to achieve wonderful results The book's authors and the publisher are listening to your feedback, and appreciate when you invest some time to let them know what you think. The first result of this collaboration is an updated version of the AJAX Chat case study that uses (and teaches) JSON instead of XML. Find this new chapter in the code download or on my website. Thanks for reading such a long message. Have fun!" Cristian Darie.
Table of Contents (17 chapters)
About the Authors
About the Reviewers

Appendix A. Preparing Your Working Environment

In order to avoid any headaches while going through the case studies in this book, it’s best to install the necessary software and configure your environment the right way from the start. Although we assume you already have some experience developing PHP applications, we’ll quickly go through the steps to install your machine with the necessary software.

The good news is that all the required software is free, powerful, and (finally!) comes with installers that make the programs easy for anyone to set up and configure. The bad news is that there are many possible configurations, so the instructions written might not apply 100% to you (for example, if you are using Windows, you may prefer to use IIS instead of Apache, and so on).

We’ll cover the installation instructions separately for Windows and *nix based machines. We’ll also cover preparing the database that is used in many examples throughout the book; these instructions apply to both Windows and *nix users, so be sure not to miss this section at the end of the appendix.

To build websites with AJAX and PHP you will need (quite unsurprisingly) to install PHP. The preferred version is PHP 5, because we use some of its features in Chapter 11. You also need a web server. We will cover installing Apache, which is the web server preferred by most PHP developers and web hosting companies. Because we’ve tried to make the examples in this book as relevant as possible for real-world scenarios, many of them need a database. We cover installing MySQL, which is the most popular database server in the PHP world. Because we used simple SQL code, you can easily use another database server without major code changes, or older versions of MySQL.

At the end of this chapter, we’ll cover installing phpMyAdmin, which is a very useful web tool for administering your databases. You’ll then learn how to use this tool to create a new database, and then a database user with full privileges to this database.

In the following pages, you’ll learn how to:

  • Install Apache 2, PHP 5, and MySQL 5 on your Windows machine

  • Install Apache 2, PHP 5, and MySQL 5 on your *nix machine

  • Install phpMyAdmin

  • Create a new database and then a database user using phpMyAdmin



    Programmers who don’t want to install the required software manually have the option of using a software package such as XAMPP, which bundles all of them (and many more) in a single installer file. XAMPP is packaged for Linux, Windows, Mac OS X, and Solaris, and is free of charge. You can get XAMPP from

    If you decide to use XAMPP, you can skip directly to setting up the ajax database, as shown at the end of this appendix.