Sessions in PHP
CSCI 2910-001 In-Class Exercise

You should be able to...

This in-class exercise will give you experience creating sessions in PHP. Specifically, it will cover:

Instructions

Begin by downloading the HTML file http://faculty.etsu.edu/tarnoff/labs2910/php/sessions.htm . This file contains two forms. The first form has four fields (item_1_quantity, item_2_quantity, item_3_quantity, and item_4_quantity) and one button labeled "Add to Session Variables". The second form is simply a single button labeled, "End Session." Both of the buttons are submit buttons. The top form calls a PHP script called session.php and the bottom form calls a PHP script session_close.php . Your assignment is to create the two php files called by the two forms and a session "logout" page.

The PHP file session.php starts/opens a session. There should be four session variables in your file called item_1_sum, item_2_sum, item_3_sum, and item_4_sum. Each time session.php is called, the values from item_1_quantity, item_2_quantity, item_3_quantity, and item_4_quantity should be added to the existing values in the corresponding session variables. Note that the first time session.php is called, is should initialize the session variables to the corresponding values sent by the form.

The second PHP file, session_close.php, should close the session using the code shown on slide 13 of today's lecture, then call your session logout page.

This is an in-class assignment, so call me over to verify its operation before you leave class today.