我在網站上有一個非常簡單的腳本。該腳本正在將HTTP POST發送到我可以控制的另一個站點。我知道如何使用cURL發送POST,但是我發送它的腳本必須對它做出響應?我要發送cURL帖子必須做的「響應」頁面是什麼?
例如,以下是發送POST的代碼(如果此腳本回顯來自站點B的響應,但我甚至不知道如何讓站點B響應該帖子) :
<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/tester.phtml");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"postvar1=value1&postvar2=value2&postvar3=value3");
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
echo $server_output;
?>
然後站點b,在後上述被髮送到URL,下面的代碼有:
<?php
$postvar1 = $_POST['postvar1'];
if ($postvar1="apples and oranges") {
$echo "This is what you see if postvar1 has been posted and is equal to apples and oranges"; } else {echo "this is what you see if postvar1 has not been posted or is not equal to apples and oranges"; }
?>
什麼需要去上的腳本,在站點b與迴應基於腳本中的「if邏輯」出現在屏幕上的文本?
你爲什麼這樣做'$ echo'? – ceejayoz 2013-03-15 15:13:34