2017-08-29 107 views
1
<?php 
    $message=$_POST["msg"]; 

    echo $message; 
    // create a new cURL resource 
    $ch = curl_init(); 
    // set URL and other appropriate options 
    curl_setopt($ch, CURLOPT_URL, "http://.../pl1.php? 
    m=$message"); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 

    // grab URL and pass it to the browser 
    curl_exec($ch); 

    // close cURL resource, and free up system resources 
    curl_close($ch); 
?> 

上面的代碼是IAM using.anyone建議我我如何得到m的值pl1.php如何從捲曲得到變量值

我收到以下錯誤: 您的瀏覽器發送的請求該服務器無法理解。

+2

'$ _GET ['m']''如何?這是PHP 101.在將其添加到URL之前,您還應該[urlencode](http://php.net/manual/en/function.urlencode.php)該消息。 –

+0

如果我們假設你的代碼沒有任何錯誤,並且它發送的請求正確,這應該在'pl1.php' - >'$ mMessage = $ _GET ['m'];''應該工作。 –

+0

因此,有沒有任何建議爲你工作?有些反饋會很好。 –

回答

2

在PHP中,作爲URL內查詢字符串傳遞的變量可在$_GET數組中訪問。

在你的情況下,它將是$_GET['m']

1

試試這個代碼:

<?php 
    $message=$_POST["msg"]; 

    echo $message; 

    // curl initialize 
    $ch = curl_init(); 

    // set curl options 
    curl_setopt($ch, CURLOPT_URL, "http://.../pl1.php? 
m=$message"); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

    // execute request and return response 
    $output = curl_exec($ch); 

    echo $output; 

    // close cURL request 
    curl_close($ch); 
?> 

並得到網頁上的數據pl1.php使用$ _GET [ 'M'];

但是,我相信用post方法使用curl發送數據比get方法好。

謝謝

+0

謝謝你的幫助。但它只適用於我想傳遞句子的一個單詞,並且由於空間的限制,它不會傳遞我正在傳遞的完整信息。要解決此問題該怎麼辦? – Nisha

+0

它的工作finally.i使用urlencode發送消息。 – Nisha

+0

祝賀:) –