I am using the following API for getting the country code using IP
http://api.hostip.info/country.php?ip=' . $IP
Example: on Localhost
$IP = '202.71.158.30';
//pass the ip as a parameter for follow URL it will return the country
$country_code = file_get_contents('http://api.hostip.info/country.php?ip=' . $IP);
and its working fine here and showing the country code.
But it showing error on Server
Example:
$IP=$_SERVER['REMOTE_ADDR'];
$country_code = file_get_contents('http://api.hostip.info/country.php?ip=' . $IP);
Showing following error:
Warning: file_get_contents(http://api.hostip.info/country.php?ip=101.63.xx.xxx) [function.file-get-contents]: failed to open stream: Connection refused in /srv/disk4/1322145/www/servername.in/app/header.php on line 12
Whats wrong with this?
$http_response_header
afterfile_get_contents
to get more info about why it failed. – Qp$http_response_header
. This variable gets populated by PHP whenfile_get_contents
is used with the HTTP wrapper and might give useful information about the HTTP request. – Qp$country_code = file_get_contents('http://api.hostip.info/country.php?ip=' . $ip); var_dump($http_response_header);
– Glycosidewget -d
from a terminal. That should give you more info about why it cannot connect to that server. – Qpwget -d -O /dev/null "http://api.hostip.info/country.php?ip=[an IP]"
and see the output. – Qp