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?
source
share