both file_get_contents and curl not working

Viewed 2801

I just used file_get_contents to retrive data in my website. But it does not returns anything.

file_get_contents("https://www.google.co.in/images/srpr/logo11w.png")

When i used the same in my local environment, It returns value.

I also tried curl in my website to figure out whether it returns anything. But it shows

Forbidden
You don't have permission to access.

I googled and i found some hints. I enabled allow_url_fopen and allow_url_include.

But nothing working.

The curl code which i have tried

function curl($url){ 
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  $return = curl_exec($ch); curl_close ($ch);
  return $return;
} 
$string = curl('https://www.google.co.in/images/srpr/logo11w.png');
echo $string;
1 Answers
Related