<html>
<head>
<title>page2</title>
<?php
session_start();
?>
</head>
<body>
<?php
print_r($_SESSION);
echo('<br><hr><br>');
print_r($_POST);
echo('<br><hr><br>');
//1 need to see if there is an array in the session variable
// if not, then we create one.
if(isset($_SESSION['arrPlayer']))
{
// we have an session variable array
// that is keep track of names
array_push($_SESSION['arrPlayer'],$_POST['fName']);
array_push($_SESSION['arrPlayer'],$_POST['lName']);
}
else
{
//There is no array in the session variable
// so we create one
// create an array
$arrPlayer = array($_POST['fName'],$_POST['lName']);
// add it to the session variable
$_SESSION['arrPlayer']=$arrPlayer;
}
echo('<br><h1>Session contents</h1><br>');
// NOTE in this example we only have 2 items fname, lname
$xcntr = 0;
for($c = 0; $c < count($_SESSION['arrPlayer']); $c++)
{
echo($_SESSION['arrPlayer'][$c]." ");
$xcntr = $xcntr+1;
// in this example we have two items
// when the xcntr gets to 2
// when enter a new line and reset the xcntr
// back to 0
if($xcntr == 2)
{
echo("<br>");
$xcntr=0;
}
}
?>
<br><hr><br>
<a href="index.php">Home</a>
</body>
</html>