Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CURLOPT_RETURNTRANSFER set to true doesnt work on hosting server

Tags:

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?

like image 496
GentSVK Avatar asked Sep 04 '12 19:09

GentSVK


2 Answers

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.

like image 94
Anthony Hatzopoulos Avatar answered Oct 20 '22 17:10

Anthony Hatzopoulos


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.

like image 22
rayalois22 Avatar answered Oct 20 '22 19:10

rayalois22