your problem is two-fold.
#1) you are setting the cookie name to "cookie[$name]" and then trying to echo out $COOKIE[$name] when in reality you are storing them in $COOKIE['cookie'][$name]
This is the fix for that:
foreach($_POST['cookie'] as $name => $age)
{
setcookie($name, $age);
echo $_COOKIE[$name];
}
or
foreach($_POST['cookie'] as $name => $age)
{
setcookie("cookie[$name]", $age);
echo $_COOKIE['cookie'][$name];
}
#2) cookie values will not be available until the next page view. That is, if you run setcookie($name, $age), then $_COOKIE[$name] will not be available in the same script execution, but will be available the next time you run the script.
When in doubt, do something like:
echo '<div align="left"><pre>';
print_r($_COOKIE)
echo '</pre></div>';
which shows you everything stored in the $_COOKIE array.