こんにちは、IPにアクセスして場所を地図に配置する必要がありますが、私が望むのはIPの現在の場所を取得することです.ISPアドレスはありません.phpでこれを行う方法を教えてください.
3 に答える
$ ipaddress = $ _ SERVER ['HTTP_HOST']; $ license_key="ライセンスキーを入力してください";
$query = "http://geoip3.maxmind.com/b?l=" . $license_key . "&i=" . $ipaddress;
$url = parse_url($query);
$host = $url["host"];
$path = $url["path"] . "?" . $url["query"];
$timeout = 1;
$fp = fsockopen ($host, 80, $errno, $errstr, $timeout)
or die('Can not open connection to server.');
if ($fp) {
fputs ($fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n");
while (!feof($fp)) {
$buf .= fgets($fp, 128);
}
$lines = explode("\n", $buf);
$data_geo = $lines[count($lines)-1];
fclose($fp);
} else {
# enter error handing code here
}
//echo $data;
$geo = explode(",",$data_geo);print_r($geo);enter code here
You can go with 3 methods :
1) API to any Geolocation db sites.
Eg : http://www.maxmind.com/en/home
2) Downloadable geolocation database which you can then refer to, to find the location once you have an ip address
Eg : http://www.hostip.info/dl/index.html
http://dev.maxmind.com/geoip/geolite << This looks good
3) Scraping from sites which shows the details. - This isnt professional, and you need to be a little tweaky to not get caught as scraper, but it gets the job done just fine.
これまでに使用したコードは何ですか? Maxmind API を使用できますが、1 日あたり 500 クエリに制限されています。
http://www.maxmind.com/en/home
PHP GeoIP 拡張機能も利用できます (コンパイル/インストールする場合)。