The cookie is set AFTER the script ends, which means that the cookie variable ($test) is going to be defined the NEXT time the script runs.
So, you can have:
setcookie("test","hello");
header("Location: page2");
and page2 (whatever it is) can say:
print $test;
// note that if register_globals is off, u'll need to use $_COOKIE['test']
Diego