Reputation: 385
PHP Curl doesn't work when tried to get contents of a specific domain.
The specific domain is 'www.net4winners.com.br', it works with every domain but not with this domain, it always returns: 'object not found' in curl output.
PHP Code of this test:
<?php
function run_curl($url,$p=null)
{
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)",
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1
);
if($p != null)
{
$options[CURLOPT_CUSTOMREQUEST] = "POST";
$options[CURLOPT_POST] = 1;
$options[CURLOPT_POSTFIELDS] = $p;
}
curl_setopt_array($ch,$options);
$resultado = curl_exec($ch);
if($resultado) { return $resultado; } else { return curl_error($ch); }
curl_close($ch);
}
$out = run_curl('http://www.net4winners.com.br/');
echo $out;
?>
could someone help me please?
Thanks.
Upvotes: 0
Views: 1926
Reputation: 24969
It's not working because the server is checking for the existence of certain headers which are not sent by cURL. Based on my testing, the one that's missing in your case is Accept-Language.
Try adding the following to your $options
array:
CURLOPT_HTTPHEADER => array('Accept-Language: en-us')
Example:
<?php
$ch = curl_init('http://www.net4winners.com.br/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept-Language: en-us'
));
curl_exec($ch);
Upvotes: 1