Curl php is not working [closed]

5

I'm using php curl on the server.

function getSite($url){
    $ch = curl_init(); 
    curl_setopt($ch,CURLOPT_URL,$url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    echo curl_error($ch);
    $output = curl_exec($ch);
    curl_close($ch);   
    echo $output;
}

getSite("http://www.google.com.br");
getSite("http://www.planalto.gov.br/ccivil_03/Constituicao/Constituicao.htm");

The google site works perfectly but the upland site does not. In localhost the 2 works. What could be happening? The 2 sites are external but only one works (the link of the site of the plateau is correct but neither error of the curl shows) Thank you in advance.

    
asked by anonymous 02.07.2016 / 01:56

1 answer

0

Apparently the site of the plateau has a user agent check to respond ... making the curl from my machine it does not work however passing a browser user agent it responds correctly.

Former via terminal:

curl -A "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5" http://www.planalto.gov.br/ccivil_03/Constituicao/Constituicao.htm

With php it would be setar:

curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5");
    
20.07.2016 / 17:36