akitchin Posted October 5, 2006 Share Posted October 5, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/23060-constructing-post-request-manually/ Share on other sites More sharing options...
HuggieBear Posted October 5, 2006 Share Posted October 5, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23060-constructing-post-request-manually/#findComment-104296 Share on other sites More sharing options...
akitchin Posted October 8, 2006 Author Share Posted October 8, 2006 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 infofwrite($fp, $header) or die('couldnt write to the test file');// send the resultswhile (!feof($fp)){ $result[] = fgets($fp, 4096);}// close the socketfclose($fp);// exitexit('<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? Quote Link to comment https://forums.phpfreaks.com/topic/23060-constructing-post-request-manually/#findComment-106006 Share on other sites More sharing options...
Barand Posted October 8, 2006 Share Posted October 8, 2006 I've never used it but is this job for cURL?http://www.higherpass.com/php/tutorials/Using-Curl-To-Query-Remote-Servers/1/ Quote Link to comment https://forums.phpfreaks.com/topic/23060-constructing-post-request-manually/#findComment-106010 Share on other sites More sharing options...
akitchin Posted October 9, 2006 Author Share Posted October 9, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/23060-constructing-post-request-manually/#findComment-106524 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.