Entry
How do I redirect both a surfer and their submitted data to another url using the POST method?
Jun 19th, 2003 08:27
Phlip, Valko Yotov, Gavin Schumaker,
resend all post vars with GET:
$getvar = "?";
while (list($key, $val) = each($HTTP_POST_VARS )) {
$getvar .= $key . "=" . URLEncode($val) . "&";
}
$location = "http://www.anothetURL.com" . $getvar;
header ("Location: $location"); /* Redirect browser new web site */
exit; /* Make sure that code below does
not get executed when we redirect. */
[Phlip:]
I changed the above code to work properly. (added call to URLEncode and
added "Location: " to header)
You can also do this POST with JavaScript:
<?
print "<FORM NAME=redirect ACTION=\"somewhere_else.php\" METHOD=POST>";
while (list($key, $val) = each($HTTP_POST_VARS ))
print "<INPUT TYPE=HIDDEN NAME=\"$key\" VALUE=\"$val\">";
print "</FORM>";
print "<SCRIPT> redirect.submit(); </SCRIPT>";
?>