Jump to content

cURL help


c_pattle

Recommended Posts

I have just installed cURL and am learn to use it but I'm not sure exactly what I am doing.  For example I have a page with this code on it. 

 

if($_GET['number'] == "6") {
    echo("<p>the number is six</p>");
}

 

Then I am trying to use cURL to send the number 6 to this page so that it returns "the number is 6".  However I am just getting an output of "1".  Below is the code I am using to try to get the output of "the number is 6". 

 

$ch2 = curl_init();

curl_setopt($ch2,CURLOPT_URL,'http://localhost/crawler/crawlertest.php');
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2,CURLOPT_POSTFIELDS,'number=6');
$return = curl_exec($ch2); 

echo ($return);

curl_close($ch2);

 

Thanks for any help

 

Link to comment
Share on other sites

$return is the return value of the operation, not the returned content if any.

 

curl_exec: Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.

 

You might only need to add this line before using curl_exec:

 

curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.