Reputation: 547
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;
Upvotes: 7
Views: 2887
Reputation: 68466
file_get_contents()
way...<?php
header('Content-Type: image/png');
echo file_get_contents("https://www.google.co.in/images/srpr/logo11w.png");
cURL
way...<?php
header('Content-Type: image/png');
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
$return = curl_exec($ch); curl_close ($ch);
return $return;
}
$string = curl('https://www.google.co.in/images/srpr/logo11w.png');
echo $string;
OUTPUT :
Upvotes: 2