I am trying to run a small website that is hosted on a distant virtual server.
My code was working fine when I was running my tests locally, on my machine through Apache 2.0.
Now that it's hosted remotely ( Apache 2 + Webmin + latest version of PHP ), seems like I'm having some issue with the famous function file_get_contents. Looks like my server doesn't allow the resolution of any external domain.
I have read multiple topics and tried many solutions but seems like none of them has worked so far.
Here is the function I have a problem with
$url='https://bitpay.com/api/rates';
$json=json_decode( file_get_contents( $url ) );
$dollar=$btc=0;
foreach( $json as $obj ){
if( $obj->code=='USD' )$btc=$obj->rate;
}
echo "1 bitcoin=\$" . $btc . "USD<br />";
$dollar=1 / $btc;
echo "10 dollars = " . round( $dollar * 10,8 )."BTC";
exit();
returns me with this error whatever I try
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in
I tried to locate the file etc/host on my server but it's inexistent.
I have no idea how to setup/parameter any hostname.
I don't have a lot of options in my Webmin panel so I'm wondering what I can do to work toward the resolution of this problem.
I have added the line allow_url_fopen = on
in my code but it doesn't work either.
Finally, I tried the curl alternative that so many of you are advising.
But when I try to echo
or print_r
the output/result, I get a blank page. Not even a single error message.