A little background: I have a form on a public website that needs to post data to an Apache server behind my firewall. I don't want to provide direct access to this webhost from the internet.
Currently this is what I'm doing: I have an IIS server in my DMZ. This IIS server is the only IP allowed to access the Apache server through the firewall. As a temporary solution I set up IIS with "Application Request Routing" to present the Apache box through IIS to the internet.
What I would like to do: Have some way to capture and then relay the form without having to present the Apache box to the internet. The trick here is that the POST will come from anywhere on the internet, be grabbed by the IIS server, and then relayed from the IIS server to the apache box. I've looked into doing this with PHP/cURL but am 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.
The first thing we faced with was the fact that after HTTP to HTTPS redirects – our POST requests lose their data. To reproduce it – let’s use the Python script mentioned above.
Generate the form within your PHP script. Use JavaScript to submit the form. The PHP function RedirectWithMethodPost () (source code further below), is called with the URL that would have been used if the redirect was the general GET redirect.
Instead of method GET, redirect browsers with method POST so the data they carry along is not revealed with the URL. This is the secret: Redirect with a self-submitting form. Generate the form within your PHP script.
Or you can print and complete the form online and bring it into your local Post Office branch. We also have application forms in our branches, so all you need to do is pay us a visit. The names and dates of birth of all people living at your old address whose post you want to redirect
The first statement I included worked properly but wasn't passing values that had multiple select options on my form. It was just populating "Array" in the fields. I corrected that by doing this:
$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 the client to be redirected to a "Thank You" page, my backend program was sending this data, but I couldn't get cURL to function with it, I worked around this by doing a header refresh and setting the value to 1. Like so:
header("refresh:1;url=http://mythankyoupage");
Thanks for the help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With