How to determine someone's city from their IP address

  1. Let's assume that you want to determine a city by IP in your PHP script.
    In this example we will use the GeoIp library.
  2. Download GeoIP PHP-module.
  3. Download free cities and countriesdatabases
  4. Include geoipcity.inc and geoipregionvars.php files from the GeoIP module to your script.
    for example:
    include("geoipcity.inc");
    include("geoipregionvars.php");
  5. Include the script city DB to your script.
    for example:
    $gi = geoip_open("/home/data_old/GeoIP-132_20070101/GeoIPCity.dat" , GEOIP_MEMORY_CACHE);
  6. Add the string
    $record = geoip_record_by_addr($gi,"your_IP");
    into your script.
    Object $record will now contain all the needed information.
    For IP 212.58.251.202 $record will be
    geoiprecord Object
    (
    [country_code] => GB
    [country_code3] => GBR
    [country_name] => United Kingdom
    [region] => B8
    [city] => Tadworth
    [postal_code] =>
    [latitude] => 51.2833
    [longitude] => -0.23339999999999
    [area_code] =>
    [dma_code] =>
    )
  7. Finally close the GeoIP DB:

    geoip_close($gi);
This service is a collection of tutorials and guides for different things
 
Why register? When you register you'll be able to write your own guides
Register
 
Dive into
 

 
Guide information