using php to perform http POST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
3po
Forum Newbie
Posts: 1
Joined: Sun Aug 06, 2006 7:17 am

using php to perform http POST

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use cURL. We have many many threads on the subject as well.
User avatar
ronverdonk
Forum Commoner
Posts: 34
Joined: Sat Jun 10, 2006 7:06 am
Location: Netherlands

Post 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>';

?>
Post Reply