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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
orbdrums
Forum Commoner
Posts: 82
Joined: Wed Sep 14, 2011 11:42 pm

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

Post 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.
benanamen
Forum Newbie
Posts: 18
Joined: Sun Nov 15, 2015 11:57 am

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

Post by benanamen »

"somethinggoeshere" should be a valid API key. Are you using one?
orbdrums
Forum Commoner
Posts: 82
Joined: Wed Sep 14, 2011 11:42 pm

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

Post by orbdrums »

I am but I didn't want to provide a fully functional api for obvious reasons.
orbdrums
Forum Commoner
Posts: 82
Joined: Wed Sep 14, 2011 11:42 pm

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

Post by orbdrums »

[SOLVED]
Using the curl_exec() function instead of get_file_contents() resolved the issue. Thanks all.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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
(#10850)
Post Reply