Jump to content


This topic is now archived and is closed to further replies.


constructing POST request manually

Recommended Posts

i have to process some of my own diddles in PHP/MySQL with some form info before i send the submitted information to its target destination.  essentially i need to middlemanhandle the form submission, but continue the request on towards its original action, which is (i assume) a PERL script.

that being said, how can i construct a POST request manually to the original *.cgi action file as though my interception never occurred?  keep in mind this is for legitimate purposes, i simply need to track some survey submissions for admin purposes before submitting the survey to its handler (no sensitive data).

i assume i'll need my headers, but i'm unsure of which to use.

Share this post

Link to post
Share on other sites
First you need to find out if the .cgi will allow you to submit from wherever you are?  Some only allow certain referrer URL's.  Assuming it does, I'd say you need a JavaScript action after you've processed the PHP to submit a hidden form.

Only way I can think to do it.


Share this post

Link to post
Share on other sites
update:  i'd rather not rely on javascript, since it shouldn't be necessary for forwarding a server-side request.  currently i am using headers and sockets, like so:

// setup the redirected form submission
$header .= "POST /test.php HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($vars) . "\r\n\r\n";
$header .= $vars."\r\n";

// open a socket with the target server
$fp = fsockopen("www.hostimworkingon.com", 80, $errno, $errstr, 30) or die('couldnt open socket stream');

// send in the header info
fwrite($fp, $header) or die('couldnt write to the test file');

// send the results
while (!feof($fp))
$result[] = fgets($fp, 4096);

// close the socket

// exit
exit('<pre>'.print_r($result, TRUE));

now that all works, as far as connecting and transmitting the info.  the problem i'm running into now is with the URI in that first header line ("POST /test.php HTTP/1.0\r\n").  i know for a fact it's there (i've tested this with a few different files), but no matter what i put in and whether the file is there or not, i'm getting a 404 response.  anyone know why this is?

Share this post

Link to post
Share on other sites
I've never used it but is this job for cURL?


Share this post

Link to post
Share on other sites
never used it myself either, but as far as i know, cURL is for intercepting the response.  ideally, i'd just like to forward the browser to the page that would normally process the form's request, but if i intercede with my data calculations i lose the POSTed info when forwarding.

i'll hash it out a little more, but thanks for your replies.

Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.