Hello.
I'm trying to loop through an array of cookies and output the values in form fields. I'm able to extract the names and the values from the array but I can't figure out how to assign the values to the variable names.
// PageOne.php - form page
<input type="text" name="Year" value="2005">
<input type="text" name="Month" value="8">
<input type="text" name="Day" value="25">
// PageTwo.php
This foreach loop sets cookies in an array.
foreach ($_POST AS $Key => $Value){
setcookie("StepFourRetry['$Key']", $Value, time()+60, "/", ".pr2market.com", 0);
}
// cookie name(s) from loop above.
StepFourRetry['Year'] // Has value '2005'.
StepFourRetry['Month'] // Has value '8'.
StepFourRetry['Day'] // Has value '25'.
// PageThree.php
// In order to extract the cookie values I've got to loop through them something like this:
foreach ($_COOKIE['StepFourRetry'] as $Name => $Value) {
echo $Name; // This outputs the names - not the values.
echo $Value; // This outputs the values - not the names.
$Name = $Value;
echo $Name; // This outputs the values - not the names.
$Name = $Value;
echo $$Name; // This outputs the values - not the names.
}
//What I'm trying to do is input the values of the cookies into a form field like this:
<input type="text" name="Year" value="$Year">
<input type="text" name="Month" value="$Month">
<input type="text" name="Day" value="$Day">
// Or like this:
<input type="text" name="Year" value="2005">
<input type="text" name="Month" value="8">
<input type="text" name="Day" value="25">
Thanks.