我关注了这个网站 How do I retrieve the visitor's ISP through PHP? 获取ISP数据,但它不再工作(无法打开流:HTTP请求失败)。我也试过用curt
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.whatismyipaddress.com/ip/132.123.23.23');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
echo $query;
但我收到以下错误:
Moved Permanently
The document has moved here.
有人知道类似的解决方案吗?
EDITED
curl解决方案仅在我的localhost上工作,遗憾的是web-host服务不允许这样做。有人知道使用file_get_contents的解决方案吗?
答案 0 :(得分:2)
设置选项
curl_setopt( $curl_handle, CURLOPT_FOLLOWLOCATION, true );
关注标题重定向。
答案 1 :(得分:0)
$ _ SERVER [ 'REMOTE_ADDR']
请注意,如果用户位于NAT防火墙后面,这可能无法正常工作。