Before you start
In this tutorial you will learn how to use HTTP authentication, streaming files, and how to create objects and exceptions in PHP.
This tutorial finishes the simple workflow application you began in the first part of this series about learning PHP. You will add HTTP authentication, the ability to stream documents from a non-web-accessible location, and exception handling. You'll also organize some of the application into objects.
Overall, you will add the ability for an administrator to approve a file, making it generally available to users. Along the way, the following topics will be discussed:
- Enabling and using browser-based HTTP authentication
- Streaming data from a file
- Creating classes and objects
- Using object methods and properties
- Creating and handling exceptions
- Controlling access to data based on the requesting page
Who should take this tutorial?
This tutorial is Part 3 of a three-part series designed to teach you the basics of programming in PHP while building a simple workflow application. It is for developers who want to learn more about advanced topics, such as using PHP for object-oriented programming. This tutorial also touches on HTTP authentication, streaming, classes and objects, and exception handling.
This tutorial assumes familiarity with the basic concepts of PHP, such as syntax, form handling, and accessing a database. You can get all the information you will need by taking "Learning PHP, Part 1" and "Learning PHP, Part 2," and by checking the Resources.
You need to have a web server, PHP, and a database installed and available. If you have a hosting account, you can use it as long as the server has PHP V5 installed and has access to a MySQL database. Otherwise, download and install the following packages:
- XAMPP
- Whether you're on Windows, Linux, or even Mac, the easiest way to get all of the necessary pieces of software for this tutorial is to install XAMPP, which includes a web server, PHP, and the MySQL database engine. If you choose to go this route, install and then run the control panel to start up the Apache and MySQL processes. You also have the option of installing the various pieces separately. Keep in mind that you will have to configure them to work together—a step already completed with XAMPP.
- Web server
- If you choose not to use XAMPP, you have several options for a web server. If you use PHP 5.4 (as of this writing, XAMPP is only using PHP 5.3.8) you can use the built-in web server for testing. For production, however, I assume that you're using the Apache Web server, version 2.x.
- PHP 5.x
- If you do not use XAMPP, you need to download PHP 5.x separately. The standard distribution includes everything you need for this tutorial. Feel free to download the binaries; you d0 not need the source for this tutorial (or ever, unless you want to hack on PHP itself). This tutorial was written and tested on PHP 5.3.8.
- MySQL
- Part of this project involves saving data to a database, so you'll need one of those, as well. Again, if you install XAMPP, you can skip this step, but if you choose to, you can install a database separately. In this tutorial, I concentrate on MySQL because it's so commonly used with PHP. If you choose to go this route, you can download and install the Community Server.




