I receive data posted to a url on my domain, check it for certain field values, update a database if necessary and then post the received data onto another url.
Unfortunately the url (https) I’m posting to doesn’t have a testbed or anything like that so I need to ensure that what I’m reposting is as it was received.
Does this look like it’s a reasonable approach?
Thanks
foreach($_POST as $key=>$value)
{
$fields_string .= $key.'='.$value.'&';
}
$fields_string = substr_replace($fields_string, "", -1);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" );
curl_setopt( $ch, CURLOPT_URL, "https://anotherdomain.com/script.php");
curl_setopt( $ch, CURLOPT_ENCODING, "" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
$response = curl_getinfo( $ch );
curl_close($ch);
$fh = fopen('audit.log', 'a');
fwrite($fh, $response."\r\n");
fclose($fh);
CURLOPT_POSTFIELDScan takearraydirectlyThis would work just fine:
You also need to manage multiple attempts in case the server is down …..