Both file_get_contents and curls do not work

I just used file_get_contents to retrieve data on my site. But returns nothing.

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

When I used the same in my local environment, it returns a value.

I also tried curl on my website to find out if it returns anything. But he shows

Forbidden
You do not have access to access.

I googled and I found some tips. I have enabled allow_url_fopen and allow_url_include .

But nothing works.

Curl code i 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; 
+7
php curl file-get-contents phpinfo
source share
1 answer

The way file_get_contents() ...

 <?php header('Content-Type: image/png'); echo file_get_contents("https://www.google.co.in/images/srpr/logo11w.png"); 

cURL method ...

 <?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; 

EXIT:

enter image description here

+2
source share

All Articles