file get contents - PHP- file_get_contents failed to open stream: Connection refused -
i using following api getting country code using ip
http://api.hostip.info/country.php?ip=' . $ip
example: on localhost
$ip = '202.71.158.30'; //pass ip parameter follow url return country $country_code = file_get_contents('http://api.hostip.info/country.php?ip=' . $ip);
and working fine here , showing country code.
but 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 open stream: connection refused in /srv/disk4/1322145/www/servername.in/app/header.php on line 12
whats wrong this?
you can use curl in place of file_get_contents()
<?php $ip = '202.71.158.30'; $runfile = 'http://api.hostip.info/country.php?ip=' . $ip; $ch = curl_init(); curl_setopt($ch, curlopt_url, $runfile); curl_setopt ($ch, curlopt_returntransfer, 1); $content = curl_exec ($ch); curl_close ($ch); echo $content;
Comments
Post a Comment