Reputation: 83
I am using this to send some info to another website and its working fine
function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($post);
curl_close($post);
}
$data = array(
"api_key" => "****",
"api_password" => "****",
"notify_url" => "www.mysite.com",
"order_id" => "$orderid2",
"cat_1" => "$cat_1",
"item_1" => "$item1",
"desc_1" => "$desc_1",
"qnt_1" => "$qty1",
"price_1" =>"$up1",
"cat_2" => "$cat_2",
"item_2" => "$item2",
"desc_2" => "$desc_2",
"qnt_2" => "$qty2",
"price_2" => "$up2",
);
post_to_url("http://website2.com/submitorder.php", $data);
When website2 receives the info its sending back an xml responce "OK-Data Received" which appears on my page. Is there something I can do to stop this message being shown on my page so the person using the site doesn't see it?
Upvotes: 2
Views: 1974
Reputation: 15919
Set the option to:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Upvotes: 0
Reputation: 29965
You have to set the CURLOPT_RETURNTRANSFER
setting :
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
That way, curl_exec($c)
will return the output instead of passing it to the browser.
CURLOPT_RETURNTRANSFER
TRUE
to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
Upvotes: 4