Veronica's SESSION Demo (Page 1)

This demo page adds one to a numeric variable and stores that value in a SESSION.
This could be used to give users an option to flip through choices.
The numeric variable in this example refers to one of twelve categories of furniture (from an array).
Click ~GOTO Page 2~ to see that the values are carried over.

The following shows the current values in this SESSION.

Array
(
    [var] => 0
    [category] => sofas
)

Current session id = dd89cf8506e84feaeda1465f1b3d0d6d

 

CODE FOLLOWS

<?php
// name & start session
session_name("furniture_categories");
session_start();

// get header file
include('includes/header.php');

// set error reporting to all
error_reporting(E_ALL);

// set variables
$start_timer time();
$var = isset($_SESSION['var']) ? $_SESSION['var'] : -1;
$category = isset($_SESSION['category']) ? $_SESSION['category'] : null;

// create items array for shopping demonstration
$items = array("sofas","recliners","kids furniture","end tables","dressers","dining tables",
    
"dining chairs","desks","coffee tables","chairs","bookshelves","beds");

// update variables
$var++;
$_SESSION['var'] = $var;
if(
$var >= && $var count($items))
{
    
$category $items[$var];
} else
{
    
$category 'N/A';
}
$_SESSION['category'] = $category;
?>
    <h1>Veronica's SESSION Demo (Page 1)</h1>

    <p>
        This demo page adds one to a numeric variable and stores that value in a SESSION.
        <br>This could be used to give users an option to flip through choices.
        <br>The numeric variable in this example refers to one of twelve categories of furniture (from an array).
        <br>Click ~GOTO Page 2~ to see that the values are carried over.
    </p>
    <p>
        The following shows the current values in this SESSION.
    </p>

<?php
echo('<pre>');
print_r($_SESSION);
echo(
'</pre>');

echo(
'<p>Current session id = ' session_id() . '</p>');

?>
    <form action="simple_session_page2.php" method="post">
        <input type="submit" value=" GOTO Page 2 ">
    </form>

<?php
// get footer file
include('../includes/footer.php');
?>