-5

Possible Duplicate:
What services can I used to find a user’s location based on their IP address?

Hii I have to access the ip and place the location on to the map but what i want is to get the current location of the ip no there isp address can some one suggest me how to do this in to the php

Community
  • 1
  • 1
Sunil Kumar
  • 1,278
  • 3
  • 14
  • 24
  • 3
    See http://stackoverflow.com/questions/37015/what-services-can-i-used-to-find-a-users-location-based-on-their-ip-address – sroes Nov 06 '12 at 09:10

3 Answers3

1

$ipaddress=$_SERVER['HTTP_HOST']; $license_key="enter your 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
heart_hacker
  • 125
  • 2
0

What code have you used so far? You can use the Maxmind API but it's limited to 500 queries per day.

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

You also have the PHP GeoIP extension available to you (If you compile / install it)

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

ajtrichards
  • 28,323
  • 13
  • 90
  • 97
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.

Kishor
  • 1,513
  • 2
  • 14
  • 25