Reputation: 44303
hey guys, i developed a website on my local apache setup on my mac. I'm using two requests to foreign domains. One goes out to geoplugin.net to get the current geolocation. This works just fine on my local setup. However when I transfer the files to my real server the website prints the following:
Warning: file_get_contents(http://www.geoplugin.net/php.gp?ip=185.43.32.341) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /home/.sites/74/site484/web/testsite/wp-content/themes/test/header.php on line 241
what can I do here? What am I doing wrong?
Furthermore I'm using a curl request on my website which doesn't retrieve data as well. Both works fine on my local mamp setup.
any ideas?
Upvotes: 1
Views: 5288
Reputation: 31
That is because geoPlugin is limited to 120 lookups per minute. http://www.geoplugin.com/premium
So, any web-site feature based on this solution can be damaged suddenly.
I would recommend to use both www.geoplugin.net/json.gp?ip={ip} and freegeoip.net/json/{ip} . And check if first one returns null (means that limit already reached) then use another one.
Upvotes: 0
Reputation: 798
You need to create an account at geoplugin.com and subscribe your domain to use the webservice without limitation, then you will stop to receive de 403 forbidden error. Don't worry about costs, it's a free service, i'm using it in three sites.
Upvotes: 1
Reputation: 41050
HTTP/1.0 403 Forbidden
means you are not allowed to access this files! Try to add an user agent header.
Upvotes: 1
Reputation: 131921
The server responds with an "403 FORBIDDEN" status code. So file_get_contents()
works fine, but the server you are trying to access (or a proxy or something in between) dont allow it.
This can have many reasons. For example (like the comment of the question) you are banned, or blocked (because of to much requests), or something.
Upvotes: 1
Reputation: 21449
try to urlencode the query string.
also I would recommend using curl extension.
Upvotes: 0