2

我正在使用它向另一个网站发送一些信息并且它工作正常

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);

当 website2 收到信息时,它会发回我页面上显示的 xml 响应“OK-Data Received”。我可以做些什么来阻止此消息显示在我的页面上,以便使用该站点的人看不到它?

4

2 回答 2

4

您必须设置CURLOPT_RETURNTRANSFER设置:

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

这样,curl_exec($c)将返回输出而不是将其传递给浏览器。


CURLOPT_RETURNTRANSFER
TRUE将传输作为 curl_exec() 的返回值的字符串返回,而不是直接输出。

于 2013-07-06T11:27:35.017 回答
0

将选项设置为:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
于 2013-07-06T11:25:39.120 回答