Jump to content

constructing POST request manually


akitchin

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.
Link to comment
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.

Regards
Huggie
Link to comment
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:

[code]<?php
// 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
fclose($fp);

// exit
exit('<pre>'.print_r($result, TRUE));
?>[/code]

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?
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.