dullnev Posted November 5, 2017 Share Posted November 5, 2017 (edited) So I wrote this code for a friends website maybe 2 years ago, and it was working perfectly until about March of this year. trying to trace through it and I'm almost certain it has to do with retrieving the data from the URL. the script uses Google geocode API to get city information from a zip code which is usually pulled from a database of users, for now I have a hardcoded zip code to make it simpler. here is what the URL should be retrieving - http://maps.googleapis.com/maps/api/geocode/json?address=32905&sensor=false here's the code(the sleep is because it may need to do multiple queries at once depending on what data is being retrieved) <?php $errorMsg = ""; $zip = "32905"; //geolocation------------------------------- function getCty($zip){ usleep(300000); $url = "http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($zip)."&sensor=false"; $result_string = file_get_contents($url); $result = json_decode($result_string, true); $result1[]=$result['results'][0]; $result2[]= $result1[0]['formatted_address']; return $result2[0]; } $u_cty = getCty($zip); $locArray = explode($zip, $u_cty); $u_city = $locArray[0]; echo $u_city; ?> Normally I would just google and find a working code snippet but this was already working for so long with no issues so I'm stumped. Any insight is greatly appreciated. Edited November 5, 2017 by dullnev Quote Link to comment Share on other sites More sharing options...
requinix Posted November 5, 2017 Share Posted November 5, 2017 So you've said implied that it's not working. Now try explaining how it's not working. Quote Link to comment Share on other sites More sharing options...
dullnev Posted November 5, 2017 Author Share Posted November 5, 2017 it does not retrieve any results, or at least it does not let me see them, I have tried echo'ing each variable after file_get_contents($url); My friend does not know PHP so I know he hasn't modified anything and I have left the website alone since I created it since we did a pretty thorough test of all the features. When I look through the database any users created since March of this year have been given blank data in the rows for city I'm not a professional developer I do it for fun for myself and friends so maybe I'm missing something or just not troubleshooting correctly Quote Link to comment Share on other sites More sharing options...
dullnev Posted November 5, 2017 Author Share Posted November 5, 2017 so after plenty of troubleshooting, I think what has happened is that Google updated their TOS to require a SSL certificate to use their API. its the best explanation so far since the code never changed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.