Hi all,
I'm trying to get the hang of Sessions using this little test program
shown below. However, the first page starts up a couple of session
variables (if they have not been started already), and invites the
user to enter a name. The second page then takes this name, adds it
to an array, and invotes the user to go back to the original page
(where hopefully his name has been added).
Any comments appreciated, Thanks
Andy
//sessionTest1.php
<?php
session_start();
header("Cache-control: private");
header("Cache-Control: no-store, no-cache, must-revalidate");
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<html>
<body>
<form action ="sessionTest2.php" method = "post">
<p>Enter your name:</p>
<input type = 'text' name = 'textEntry'/>
<input type = 'submit' value='submit'/>
</form>
<?php
$condition=isset($names);
if(!$condition)
{
$names = array();
$i = 0;
$_SESSION['i'] = $i;
$_SESSION['names'] = $names;
}
else
{
$names = $_SESSION['names'];
for($i=0; $i<count($names); $i++)
{
echo "$names[$i]";
}
}
?>
</body>
</html>
-------------------------------------------------------------------------
//sessionTest2.php
<?php
session_start();
header("Cache-control: private");
header("Cache-Control: no-store, no-cache, must-revalidate");
?>
<html>
<body>
<form action = 'sessionTest.php' method = 'post'>
<input type = 'submit' value = 'back'/>
<?php
$names = $_SESSION['names'];
$count = $_SESSION['count'];
$lastName = $_POST['textEntry'];
$names[$count] = '$lastName';
$_SESSION['names'] = $names;
$tester = $_SESSION['names'];
echo $tester[0];
//header("Location: sessionTest.php?output=$foo");
?>
</form>
</body>
</html>