-5

重複の可能性:
IP アドレスに基づいてユーザーの場所を見つけるために使用できるサービスは何ですか?

こんにちは、IPにアクセスして場所を地図に配置する必要がありますが、私が望むのはIPの現在の場所を取得することです.ISPアドレスはありません.phpでこれを行う方法を教えてください.

4

3 に答える 3

1

$ 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
于 2012-11-06T09:17:22.453 に答える
0

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.

于 2012-11-06T09:20:33.900 に答える
0

これまでに使用したコードは何ですか? Maxmind API を使用できますが、1 日あたり 500 クエリに制限されています。

http://www.maxmind.com/en/home

PHP GeoIP 拡張機能も利用できます (コンパイル/インストールする場合)。

http://php.net/manual/en/book.geoip.php

于 2012-11-06T09:12:32.073 に答える