PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Sep 19, 2018 5:04 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Jun 18, 2018 8:54 pm 
Offline
Forum Commoner

Joined: Wed Sep 14, 2011 11:42 pm
Posts: 82
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.
Syntax: [ Download ] [ Hide ]
<?
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.


Top
 Profile  
 
PostPosted: Mon Jun 18, 2018 9:40 pm 
Offline
Forum Newbie

Joined: Sun Nov 15, 2015 12:57 pm
Posts: 18
"somethinggoeshere" should be a valid API key. Are you using one?


Top
 Profile  
 
PostPosted: Mon Jun 18, 2018 9:45 pm 
Offline
Forum Commoner

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


Top
 Profile  
 
PostPosted: Tue Jun 19, 2018 2:13 pm 
Offline
Forum Commoner

Joined: Wed Sep 14, 2011 11:42 pm
Posts: 82
[SOLVED]
Using the curl_exec() function instead of get_file_contents() resolved the issue. Thanks all.


Top
 Profile  
 
PostPosted: Wed Jun 20, 2018 12:34 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13575
Location: New York, NY, US
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)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group