Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting HTTP form post

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.

like image 635
jqapi Avatar asked Oct 26 '12 17:10

jqapi


People also ask

Do post requests lose their data after HTTP to https redirects?

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.

How do I redirect a form in PHP?

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.

How to redirect browsers with post instead of get?

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.

How do I redirect a post to another address?

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


1 Answers

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!

like image 95
jqapi Avatar answered Sep 25 '22 03:09

jqapi