redirect using post
Moderator: General Moderators
-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am
redirect using post
The names here have been changed to protect the innocent. And make it easier to understand.
I have a payment page in domain A, which passes info via a POST to payment handling company B. The format of B's site means that info must come via POST, and must come from domain A.
Now I'm setting up another site on domain C, so I need to send the payment info to domain A, and redirect it (via post) to C.
But I'm having trouble redirecting info using post. How do I do it?
I have a payment page in domain A, which passes info via a POST to payment handling company B. The format of B's site means that info must come via POST, and must come from domain A.
Now I'm setting up another site on domain C, so I need to send the payment info to domain A, and redirect it (via post) to C.
But I'm having trouble redirecting info using post. How do I do it?
I'm pretty sure you can set the headers to think it was a post, I'll research and get back to you on that...
the other alternative would be to use a form and submit it on body load:
ex:
the other alternative would be to use a form and submit it on body load:
ex:
Code: Select all
<html>
<body onLoad="e;document.MyForm.submit()"e;>
<form name="e;MyForm"e; method="e;post"e; action="e;c.php"e;>
<input type="e;hidden"e; name="e;myVar"e; value="e;your value"e;>
</form>
</body>
</html>-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
do you mean:
and all info must be the same?
If it is, post the code in A telling that received infos from B for me to understand it better.
Code: Select all
A send to B back to A send to CIf it is, post the code in A telling that received infos from B for me to understand it better.
-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
Using just header("location: ".$url) to redirect will loose all post variables received by A.
Instead doing that, gather all these variables in A script and then resubmit it to C script using hidden fields.
Then the C script will receive all these infos as if it came from B.
If you have any questions about that, just lemme know. ok?
Instead doing that, gather all these variables in A script and then resubmit it to C script using hidden fields.
Code: Select all
// receive
$name = $_POST['name'];
$age = $_POST['age'];
// build resubmission form
echo "
<form name=thisfrm method=post action='script_c.php'>
<input type=hidden name=name value='$name'>
<input type=hidden name=age value=$age>
</form>";
// resubmit
echo "
<script language='javascript'>
document.thisfrm.submit();
</script>";If you have any questions about that, just lemme know. ok?
Last edited by harrisonad on Fri May 27, 2005 5:16 am, edited 1 time in total.
-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am
Searched on google and found this page: http://codewalkers.com/archives/phpcoding/8293.html
Google search...
Google search...
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
There is also cURL that might be of interest.hessodreamy wrote:That would do the trick, but only if the client has javascript enabled. I need something a bit more foolproof.
-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am
I tried the code from codewalkers, but it didnt seem to do anything. Here's the code used:
All I get is the 'end script'
I've tried cURL but apparently that just downloads a page, and does not pass control to it, which is what I need.
I get a similar blank page from a lot of scripts found. Am I doing something fundamentally wrong?
Code: Select all
// Site information
$site = "localhost";
$url = "/print.php";
// Build your POST query
$req = "user=USERNAME&pass=PASSWORD";
// Header info to connect to the server
$header .= "POST $url HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= 'Content-Length: ' . strlen($req) . "\r\n\r\n";
// Open up a connection on port 80 to server
$fp = fsockopen ($site, 80, $errno, $errstr, 30);
// Can't connect? Then DIE!
if (!$fp)
die("I couldn't connect to $site");
// send POST request
fputs ($fp, $header . $req);
// Receive POST request
while ( !feof($fp) )
$response = @fread($fp,1024);
// $response = entire page
print $response;
echo "end script";I've tried cURL but apparently that just downloads a page, and does not pass control to it, which is what I need.
I get a similar blank page from a lot of scripts found. Am I doing something fundamentally wrong?