CURL PHP does not work if CURLOPT_RETURNTRANSFER is set to true

I am trying to extract the site HTML code via cURL for PHP. It usually works fine, but there are some websites, the answer is empty. For example, if the following script is executed for the alditalk.de URL:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.alditalk.de/');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/4");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = curl_exec($ch);
curl_close($ch);

In this case, the variable is $dataempty. The strange thing is that if I change curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);to curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);, the website will be printed on the screen. The problem is that I need the contents in the variable for further operations.

I tried it locally on WAMPP as well as on my Hoster. I also tried to set some header information without success. There are no errors either. Are there any solutions?

+4
source share
3 answers

. , curl.

XAMPP,

;extension=php_curl.dll

xampp\apache\bin\php.ini, Apache.

. XAMPP PHP xampp xampp\php\php.ini.


WAMP SERVER

:

  • WAMP ( )
  • WAMP\bin\php\(your version of php)\
  • php.ini
  • , extension=php_curl.dll
  • WAMP\bin\Apache\(your version of apache)\bin\
  • php.ini
  • , extension=php_curl.dll
  • WAMP
0

.. , curl . xampp??

Go to http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/ 

curl, php.

0

, . ob_start() , ?

The idea above is, of course, a hacker way to solve it. Before returning to ob_start (), I would suggest double checking all variable names, ini settings, etc., since it is always possible that you are doing something like random access to the contents of $ daya, not $ data - this is exactly what i just spent 45 minutes about in my own script. Correcting my variable name fixed an incorrect behavior that initially led me to this issue.

Hoping this helps someone. Hooray!

0
source

All Articles