I am reusing a curl function from a long time ago that is now acting differently than I remember. In this particular case, I'm authenticating a user's Twitter credentials. Here's the code as it stands now:
$cred = $_POST['twitter_username'].':'.$_POST['twitter_password'];
$url = "http://twitter.com/account/verify_credentials.json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_GET, 0);
curl_setopt($ch, CURLOPT_USERPWD, $cred);
$result = curl_exec ($ch);
curl_close ($ch);
This is working fine for the authentication, but is outputting the whole JSON response to the browser, which I don't want to do.
I'm not very familiar with curl. I tried setting CURLOPT_VERBOSE to 0 and false, but neither worked. I'm sure this is a pretty simple change somewhere, but I'm lose on what it is.
Thanks
You need this option:
curl_setopt(CURLOPT_RETURNTRANSFER, true);
From the curl docs:
CURLOPT_RETURNTRANSFER
: TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With