0

After making two cURL requests the second request I want to capture the returned HTML and pass it back to the calling function as a string. Right now it instead outputs the HTML to the client. I've messed with ob_end_clean() and ob_get_contents() without success.

Here is what I currently have...

function stuff()
{
 //user/pass stuff omitted.

 $ch = curl_init();
 curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
 curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
 curl_setopt($ch,CURLOPT_HEADER,0);
 curl_setopt($ch,CURLOPT_URL,$url);
 curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
 curl_setopt($ch,CURLOPT_COOKIEFILE,$cookies);
 curl_setopt($ch,CURLOPT_POSTFIELDS,"user=$cp_user&pass=$cp_pwd");
 curl_setopt($ch,CURLOPT_TIMEOUT,100020);

 ob_start();
 $f = curl_exec($ch);
 $h = curl_getinfo($ch);
 $p0 = explode('cpsess',$h['url']);
 $p1 = explode('/',$p0[1]);
 ob_end_clean();

 /***/
 ob_start();
 curl_setopt($ch,CURLOPT_URL,$q2a.$p1[0].$q2b);
 curl_setopt($ch,CURLOPT_HEADER, 0);
 curl_exec($ch);
 $r = ob_get_contents();
 ob_end_clean();
 /***/

 curl_close($ch);

 return $r;
}

1 Answer 1

1

Use

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

And then catch the returned content with

function stuff() {
    // function code before

    $r = curl_exec($ch);

    // function code after

    return $r;
}

Don't use any ob_ functions for this because if the CURLOPT_RETURNTRANSFER is not set explicit to true or 1 curl won't return or print out any content from the request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.