Forum Moderators: coopster

Message Too Old, No Replies

Using a PHP to send POST data

I want to intercept and manipulate POST data before sending it on

         

Igau

4:38 pm on Jul 13, 2004 (gmt 0)

10+ Year Member



I'll try and keep this brief...

Basically I'm submitting from form1.php to [remote.server.com...] using POST. This works fine on it's own, but I want to introduce a PHP script in the middle to do some data manipulation before proceeding onwards.

After successfully setting up $postdata, I'm using this to try and send it...

sendPOST($postdata,"/anotherscript.asp");

function sendPOST($PostData, $Uri) {

$ContentLength = strlen($PostData);
$Host = "remote.server.com";
$Script = $Host . $Uri;
header("location: $Script");

$ReqHeader =
"POST $Uri HTTP/1.0\n".
"Host: $Host" . ":443\n".
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $ContentLength\n\n".
"$PostData";

// Open the connection to the host
$socket = fsockopen($Host, "443");

if($socket) {

fputs($socket, $ReqHeader);

//while (!feof($socket)) {
// $result .= fgets($socket,1024);
//}

}

fclose($socket);

if($result) echo $result;

}


However, I seem to be sending data from form1.php instead of the form I put in the middle... Can anyone help? I'm totally stuck on this and I have a pretty tight work deadline (2 days left now)...

[edited by: Igau at 4:40 pm (utc) on July 13, 2004]

stevenmusumeche

4:39 pm on Jul 13, 2004 (gmt 0)

10+ Year Member



I believe this can be done using the cURL functions.

Igau

4:55 pm on Jul 13, 2004 (gmt 0)

10+ Year Member



Just tried using cURL instead... I get exactly the same thing...

$URL = $Host . $Uri;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
curl_exec ($ch);
curl_close ($ch);
header("location: myserver/script.asp);

If I miss out the header("location") part, it doesn't redirect to the page I'm submitting data to... I must be doing something fundamentally wrong somewhere here.

Igau

10:36 pm on Jul 13, 2004 (gmt 0)

10+ Year Member



Sorry, but bumping this... nobody got any ideas? I'm desperate to get this sorted out ASAP!