更新时间:2023-02-21 19:43:03
这是我使用的方案.如果它没有得到一个 GET 变量,它就会使用用户的远程地址.
Here's one that I use. If it doesn't get a GET var it uses the user's remote address.
<?php
if(!empty($_GET['ip'])){
if(preg_match('!^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$!',$_GET['ip'])){
$ip_address=$_GET['ip'];
} else {
print ("invalid ip address");
}
} else {
$ip_address=$_SERVER['REMOTE_ADDR'];
}
$test = file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip_address);
$test = unserialize($test);
print "<html><pre>";
print_r ($test);
print "</pre></html>";
?>