2

I'm trying to use the http://ip-api.com/json/ api for get and show the information of a visitant that conects to my website on hostinguer.com.

When I do the next, it should responds me with a json with all the info in a json format:

echo file_get_contents("http://ip-api.com/json/{$user_ip}");

But I get the following error message:

Warning: file_get_contents(http://ip-api.com/json/[MY PUBLIC IP]): failed to open stream: Connection refused in /home/[HOSTINGUER USER]/public_html/ip2.php on line 31

And other strange thing: if I use another API it works correctly and returns me the correct Json! The other API command:

echo file_get_contents("http://ipinfo.io/{$user_ip}/json");

So, I want to use the ip-api.com API cause the results are more accurate, but only works if I use ipinfo.io API... Why can I do the petition to a website and not to the other?

Otherwhise, I tried both in local using curl or writting in my webrowser and it works correctly. Also I tried in local in a Lammp and the both works perfectly. And finally I tried somthing like this post: PHP file_get_contents() returns "failed to open stream: HTTP request failed!" in hostinguer and it doesn't works..

I thought maybe is something in the hostinguer configuration but...

Thanks in advance!

Community
  • 1
  • 1
selan
  • 956
  • 3
  • 11
  • 27
  • perhaps it is a routing restriction put in place... try doing a file_get_contents for any other website (google.com or stackoverflow.com,etc) and see if you get a connection refused error. – Clay Sep 30 '15 at 10:44
  • They're probably doing some user agent detection, try sending a valid user agent string either using curl or the [`$context`](http://php.net/manual/en/function.file-get-contents.php) argument – andrew Sep 30 '15 at 10:48

1 Answers1

0

Your IP address is banned. If you're using normal web hosting, your outgoing IP address is shared with other users, who probably did more requests than allowed.

Go to http://ip-api.com/docs/unban and enter your server's outgoing IP address (check it via http://ipinfo.io/json)

Vlad
  • 53
  • 1
  • 6