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;
cURL is capable of much more than file_get_contents . That should be enough. FWIW there's little difference with regards to speed. I've just finished fetching 5,000 URLs and saving their HTML to files (about 200k per file).
Short answer: No. file_get_contents is basically just a shortcut for fopen, fread, fclose etc - so I imagine opening a file pointer and freading it isn't cached.
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 :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With