Jump to content


constructing POST request manually

  • Please log in to reply
4 replies to this topic

#1 akitchin

  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 05 October 2006 - 06:59 AM

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.

#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 05 October 2006 - 04:03 PM

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.

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 akitchin

  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 08 October 2006 - 10:25 PM

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?

#4 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 08 October 2006 - 10:38 PM

I've never used it but is this job for cURL?

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 akitchin

  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 09 October 2006 - 09:56 PM

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users