faqts : Computers : Programming : Languages : PHP : Function Libraries : HTTP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

24 of 69 people (35%) answered Yes
Recently 5 of 10 people (50%) answered Yes

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>";
?>