Page 1 of 1

using php to perform http POST

Posted: Sun Aug 06, 2006 7:37 am
by 3po
Hi

I have a rather confusing problem but i'll try and explain.

i am looking for a php function that can perform a manual http POST to a third party action page. Essentially, user email addresses are to be sent to a third party action page (in addition to my own) for entry into their database. However, this must be transparent to the user, as i dont want them to have to click 'submit' twice to send the data to two different action pages, and i dont want them to be redirected to the third party website!

i dont have direct access to the third party database myself, hence the email addresses must be sent via their action page and cannot be inserted directly.

i have found a function http_post_data() that looks like it may perform the action i'm looking for, but it is very poorly documented on the php site. Does anyone have experience of this function who could give me some more info or ideally examples of its use? Is there perhaps a more suitable method of performing this task?

Any help is greatly appreciated.

Cheers, Rich
:wink:

Posted: Sun Aug 06, 2006 7:40 am
by feyd
use cURL. We have many many threads on the subject as well.

Posted: Tue Aug 08, 2006 4:44 pm
by ronverdonk
A good site to start cURL is http://curl.haxx.se/libcurl/php/.

A sample of what you are looking for is the following piece of code. One program does the POST, the other one is posted.
Remember, it is just a sample I copied from the mentioned site, the way you have to adapt and use it is up to you!

Code: Select all

-------------- POST via cURL  ------------------------------------------------

<?php

// create a new curl resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://path/to/your/site/b.php");

// Do a POST
$data = array('name' => 'Dennis', 'surname' => 'Pallett');

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

// grab URL, and print
curl_exec($ch);

?>
------------------ and the receiving B.PHP -----------------------
<?php

echo '<h3>Form variables I received: </h3>';

echo '<pre>';
print_r ($_POST);
echo '</pre>';

?>