Page 1 of 1
cURL Post Foward
Posted: Fri Jul 25, 2008 2:12 pm
by tecktalkcm0391
Hello,
I'm having problems taking everything that is posted to a page and sending it via cURL... I just can't figure it out... how do I take everything posted to pageA and send it to pageB on a different server.... each time the POST has different information..
Thanks!
Re: cURL Post Foward
Posted: Fri Jul 25, 2008 3:10 pm
by Christopher
What part is not working? You need to take the $_POST vars and build a cURL request from them. See the manual or be more specific on where the problem is occurring.
Re: cURL Post Foward
Posted: Fri Jul 25, 2008 6:51 pm
by JellyFish
I didn't know you could make HTTP POST requests with cURL? I thought your only option was fsockopen.
Re: cURL Post Foward
Posted: Fri Jul 25, 2008 9:39 pm
by Christopher
cURL has options: CURLOPT_HTTPGET, CURLOPT_POST, CURLOPT_PUT, plus CURLOPT_CUSTOMREQUEST.
Re: cURL Post Foward
Posted: Sat Jul 26, 2008 1:16 am
by JellyFish
Awesome! Thanks arborint for that epiphany!
I managed to wip up a cURL that sends POST requests to a page. If you want all the $_POST fields to be sent to another page that's on another server try something like this:
Code: Select all
<?php
$data = $_POST;
$ch = curl_init("http://url.com/path/file");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CUROPT_POSTFIELDS, $data));
curl_exec($ch)
curl_close($ch);
?>
Something like that. You can also only send individual fields by redefining the $data definition:
Code: Select all
$data = array("name" => $_POST['name'], "whatever" => $_POST['whatever']);
Just as long as $data is an array it'll work.
Hope that helps.
Re: cURL Post Foward
Posted: Sat Jul 26, 2008 1:50 am
by Christopher
To quote Kieran (twice) -- I heart cURL and cURL FTW!