如何从卷曲得到变量值

问题描述:

<?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

因此,有没有任何建议为你工作?有些反馈会很好。 –

在PHP中,作为URL内查询字符串传递的变量可在$_GET数组中访问。

在你的情况下,它将是$_GET['m']

试试这个代码:

<?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

祝贺:) –