Form HTTP redirection

A bit of background: I have a form on a public website that should send data to the apache server behind my firewall. I do not want to provide direct access to this web host from the Internet.

This is currently what I am doing: I have an IIS server in my DMZ, this IIS server is the only IP address available to access the apache server through the firewall. As a workaround, I install IIS using Application Request Routing to present the Apache window through IIS to the Internet.

* What I would like to do: * Be able to somehow capture and then submit the form without presenting the Apache box on the Internet. The trick here is that the POST will come from anywhere on the Internet, be captured by the IIS server, and then transferred from the IIS server to the apache field. I learned this with PHP / cURL, but not sure if using something like this will do the trick:

<?php $todo = ""; while (list($name, $value) = each($HTTP_POST_VARS)) { $todo.=$name."=".$value."&"; } $ch = curl_init('http://mylanserver/capture.php'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $todo); curl_exec ($ch); curl_close ($ch); ?> 

Can someone point me in the right direction? Thanks.

+7
source share
3 answers

The first statement I turned on worked correctly, but did not pass values ​​that had several choices in my form. It was just filling the "Array" in the margins. I fixed this by doing the following:

 $postParams = file_get_contents("php://input"); $ch = curl_init('http://mysite/capture.php'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postParams); curl_exec ($ch); curl_close ($ch); 

Then I needed to redirect the client to the "Thank you" page, my backend program sent this data, but I could not get cURL to work with it, I worked on it by updating the header and setting the value to 1. For example:

 header("refresh:1;url=http://mythankyoupage"); 

Thanks for the help!

+3
source

If I understand you correctly, do you want to send these messages?

try the following:

 $url = 'http://server.com/path'; $data = array('key1' => 'value1', 'key2' => 'value2') // use key 'http' even if you send the request to https://... $options = array('http' => array( 'method' => 'POST', 'content' => http_build_query($data) )); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); 

you don’t need to build the $ data array yourself, you can just pass the $ _POST array.

0
source

Use snoopy. This will help you a lot. Or save the data in some temporary DB, create a small bot (you can use snoopy again) and let it communicate with the web server and play with the data as you like. Schedule this bot as a cron in the cron tab.

0
source

All Articles