Reputation: 1313
I am sending the request to google maps api services to calculate the distance like this url:
$apiURL = "http://maps.google.com/maps/geo?&output=xml&key=AIzaSyCYz5Kpw4xTYVwAUibaMIUVBcaL-RfTumk&q=myAddress"
I am trying to get the response using file_get_contents($apiURL)
, & it is working well with my Local system. When i uploaded the same file to the server, the output of file_get_contents($apiURL)
is appearing to be null & giving error like -
Warning:
file_get_contents(http://maps.google.com/maps/geo?&output=xml&key=AIzaSyCYz5Kpw4xTYVwAUibaMIUVBcaL-RfTumk&q=Aerekere
%2Cbangalore%2Ckarnataka) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /mnt/stor2-wc1-dfw1/410304/hfg.mpadusa.com/web/content/components/com_helping/controllers/distance.php
on line 108.
I have checked couple of things like
What might me the issue. Any help is really appreciated.
Upvotes: 2
Views: 6243
Reputation: 17710
file_get_contents is often disabled/blocked on web servers due to security risks when accessing external content (e.g. through http).
As a matter of good practice, always use curl functions to get external content, including calls to the google API. You can find plenty of examples of using curl on the web, but a simple place to start is the manual: https://www.php.net/curl_exec
Upvotes: 1