Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

Learning PHP, Part 3: Authentication, objects, exceptions, and streaming

Nicholas Chase is the founder and creator of NoTooMi. In addition to technical writing for large corporations, he has been involved in website development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. He has been a high school physics teacher, a low-level-radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, an Oracle instructor, and the chief technology officer of an interactive communications company. He is the author of several books, including XML Primer Plus (Sams 2002).

Summary:  This tutorial is Part 3 of a three-part "Learning PHP" series teaching you how to use PHP through building a simple workflow application. In this tutorial, you will learn about using HTTP authentication, streaming files, and how to create objects and exceptions.

03 Jan 2013 - Nicholas Chase updated content throughout this tutorial to reflect current PHP technology.

View more content in this series

Date:  03 Jan 2013 (Published 12 Jul 2005)
Level:  Intermediate PDF:  A4 and Letter (792 KB | 36 pages)Get Adobe® Reader®

Comments:  

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.

About this tutorial

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.


Prerequisites

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.

1 of 11 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Linux, XML
ArticleID=133669
TutorialTitle=Learning PHP, Part 3: Authentication, objects, exceptions, and streaming
publish-date=01032013
author1-email=ibmquestions@nicholaschase.com
author1-email-cc=