我正在使用Geoplugin来检索用户的当前位置。除数据错误外,一切正常。我的国家阿曼但输出是美国。
请注意,我没有使用VPN或代理。
代码:
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = unserialize(file_get_contents_curl('http://www.geoplugin.net/php.gp?'.$_SERVER['REMOTE_ADDR']));
$orig_lat = $url["geoplugin_latitude"];
$orig_lon = $url["geoplugin_longitude"];
echo $orig_lat;
echo $orig_lon;
我还使用cUrl而不是file_get_contents,因为服务器中的allow_url_fopen处于关闭状态。
输出:
41.877602 -87.627197
修改 我发现我忘了在网址上写ip。 http://www.geoplugin.net/php.gp?ip=
问题已解决:)
答案 0 :(得分:0)
使用您的代码可以将真实的coordenates返回到我的位置。
Geoplugin使用MaxMind DB获取数据,您可以查看此来源。