Categories
PHP

Redirect Form – PHP

You want to redirect a form with all his data?

This is a simple solution to use with php.

Paste this code where was your original form:

foreach($_POST as $key=>$value) {
  $fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');

// Create a curl handle to domain 2
$ch = curl_init('http://neeurltoredirect.com');

//configure a POST request with some options
curl_setopt($ch, CURLOPT_POST, true);
//put data to send
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
//this option avoid retrieving HTTP response headers in answer
curl_setopt($ch, CURLOPT_HEADER, 0);
//we want to get result as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//execute request
$result = curl_exec($ch);

//show response from domain 2 to client if needed
die($result);