WebSys Pizza Server (PHP Sessions)

This sample PHP program demonstrates the use of PHP session variables. This system involves a single program, although this program can handle a number of different kinds of requests. The examples we have discussed in the past have involved multiple CGI programs, this one involves only one. The single program (pizza.php) can act in different ways depending on the query received, specifically it looks at the form field named "formname" and does the following:

Value of
formname
Resulting Action
none If a session already exists, send back an order form.
If no session, sends back a login form.
login Validates the name and password, and if valid sends back an order form. Also sets a session variable named 'username'the user name as the value.
order Validates the order and if valid sends back a receipt

The system includes a login form that allows a user to log on to the system using a name and password. The program reads names and passwords from a file name "pw". The username "joe" and the password "pizza" are already set up in the file "pw".

Once the user logs in, the program sends back a pizza order form and sets a session variable to record the user's name. When the order form is submitted, the program determines the user name from the session variable.

Much of the HTML that is generated by the PHP program is read from files. This makes it possible to change the look of the site without changing the PHP program itself.


FILES:

pizza.php

The PHP program. One program handles the entire system. Click on this link and you will get the login page. See below to actually see the source code.

logo

The WebSys Pizza logo that shows up on the top of all pages.

pizzaguy.gif

A graphic image included in the logo.

loginform.tmpl

The HTML form a user uses to log in to the pizza server.

orderform.tmpl

Most of the HTML form for ordering a pizza.

pizzaphp.html

Source code for the PHP program

pizza.zip

Zip file containing everything.