In your example, you wouldn't see the $_SESSION until you refreshed.
1st Pass: $_SESSION prints and $_SESSION['name'] is not set
2nd Pass: $_SESSION prints nothing because it still is not declared, $_SESSION['name'] gets declared after the print
3rd Pass: Old $_SESSION prints and then new post changes to $_SESSION['name']
Try rearranging it a bit:
session_start();
$_SESSION['name'] = $_POST['name'];
print_r($_POST);
print_r($_SESSION);
$str = "<form method=post action=" . $_SERVER[PHP_SELF] . ">";
$str .= "<input name=name type=text>";
$str .= "<input name=cmd type=submit value=Send>";
$str .= "</form>";
echo($str);
Thanks for the suggestions guys! I tried both code sample and they worked as expected but unfortunately did not solve my problem. What I am look for is the value of the POST variable from the previous pass not the current pass.
My original test code was:
session_start();
print_r($_POST);
print_r($_SESSION);
$str = "<form method=post action=" . $PHP_SELF . ">";
$str .= "<input name=name type=text>";
$str .= "<input name=cmd type=submit value=Send>";
$str .= "</form>";
echo($str);
$_SESSION['name'] = $_POST['name'];
Running this code on IE7 produces the following results:
First pass:
Array ( [name] => abc [cmd] => Send )
Array ( [name] => )
Second pass:
Array ( [name] => xyz [cmd] => Send )
Array ( [name] => abc )
Third pass:
Array ( [name] => 123 [cmd] => Send )
Array ( [name] => xyz )
Running this code on IE6 and Firefox produces the following results:
First pass:
Array ( [name] => abc [cmd] => Send )
Array ( [name] => )
Second pass:
Array ( [name] => xyz [cmd] => Send )
Array ()
Third pass:
Array ( [name] => 123 [cmd] => Send )
Array ()
Note that there is nothing in the session array for the IE6 / Firefox passes. What am I missing???
Thanks HeidiR