I'm trying to process result from $data = curl_exec($ch);
instead of printing it on the screen. In order to achieve that I set the option CURLOPT_RETURNTRANSFER
to true
like this:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
On my local server this works as expected but when I put the same file online on my server it doesn't work.
When I set CURLOPT_RETURNTRANSFER
to false
it works.
What am I doing wrong?
If you set CURLOPT_RETURNTRANSFER
to true
or 1
then the return value from curl_exec
will be the actual result from the successful operation. In other words it will not return TRUE
on success. Although it will return FALSE
on failure.
As described in the Return Values section of curl-exec
PHP manual page: http://php.net/manual/function.curl-exec.php
You should enable the CURLOPT_FOLLOWLOCATION
option for redirects but this would be a problem if your server is in safe_mode
and/or open_basedir
is in effect which can cause issues with curl as well.
If it works fine on your local environment, probably your remote server's IP is being blocked by the server at the target URL you've set for cURL to use. You need to verify that your remote server is allowed to access the URL you've set for CURLOPT_URL.
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