我用下面的API用於獲取使用IPPHP的的file_get_contents未能打開流:連接被拒絕
http://api.hostip.info/country.php?ip=' . $IP
實例國家代碼:上本地主機
$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);
及其工作罰款這裏顯示國家代碼。
但它顯示服務器上的錯誤
例子:
$IP=$_SERVER['REMOTE_ADDR'];
$country_code = file_get_contents('http://api.hostip.info/country.php?ip=' . $IP);
顯示以下錯誤:
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
請告訴我問題呢?
也許這與PHP和更多的網絡限制有關。嘗試在'file_get_contents'之後轉儲'$ http_response_header'以獲取有關失敗原因的更多信息。 – marekful 2013-04-05 13:33:08
確保你可以用fopen打開一個url。請參閱:http://php.net/file_get_contents#refsect1-function.file-get-contents-notes – 2013-04-05 13:33:17
@MarcellFülöp:但它的工作localhost只顯示在服務器上的錯誤。那麼它是$ _SERVER ['REMOTE_ADDR']的問題; ? – Sky 2013-04-05 13:37:11