Page 1 of 1

api works in dev and test but not on Network Solutions...

Posted: Mon Jun 18, 2018 8:54 pm
by orbdrums
I have some code that works just fine on my DEV and TEST environments but returns nothing in PROD (Network Solutions hosted). I am including the code and am looking for any suggestions. I have used just the API call and it works fine from multiple machines AND as an HTML file in PROD, but when the following will not return data in PROD.

Code: Select all

<?
session_start();
$jsonurl = "http://api.openweathermap.org/data/2.5/weather?q=Boston&appid=somethinggoeshere";
$json = file_get_contents($jsonurl);
$weather = json_decode($json);
$kelvin = $weather->main->temp;
$celcius = $kelvin - 273.15;
$fahrenheit = round($celcius * 1.8 + 32);
$pressure = $weather->main->pressure;
$desc = $weather->weather->description;
echo 'Irvine: '.$fahrenheit.' Description: '.$pressure;
echo '<br/>OpenWeatherMap Data: '.$json;
?>
Many thanks in advance.

Re: api works in dev and test but not on Network Solutions..

Posted: Mon Jun 18, 2018 9:40 pm
by benanamen
"somethinggoeshere" should be a valid API key. Are you using one?

Re: api works in dev and test but not on Network Solutions..

Posted: Mon Jun 18, 2018 9:45 pm
by orbdrums
I am but I didn't want to provide a fully functional api for obvious reasons.

Re: api works in dev and test but not on Network Solutions..

Posted: Tue Jun 19, 2018 2:13 pm
by orbdrums
[SOLVED]
Using the curl_exec() function instead of get_file_contents() resolved the issue. Thanks all.

Re: api works in dev and test but not on Network Solutions..

Posted: Wed Jun 20, 2018 12:34 pm
by Christopher
The problem may be allowed stream wrappers. See:

http://php.net/manual/en/wrappers.php

And also the manual on fopen wrappers:

http://php.net/manual/en/filesystem.con ... -url-fopen