所以我试图让下面的代码工作,但由于某种原因,即使url有效并且如果我通过粘贴到浏览器中访问它也可以工作,但curl永远不会正确执行。我应该得到一个返回的字符串,但是当使用这个php curl脚本时,我什么也得不到。有什么想法吗?
<?php
$username ='';
if(isset($_POST['user'])){
$username = $_POST['user'];
}
$query = 'whitelist add '.$username;
$command=urlencode($query);
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://IPHERE/console?command=whitelist+add+sad");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
echo curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>