sample_city.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/php -q
  2. <?php
  3. // This code demonstrates how to lookup the country, region, city,
  4. // postal code, latitude, and longitude by IP Address.
  5. // It is designed to work with GeoIP/GeoLite City
  6. // Note that you must download the New Format of GeoIP City (GEO-133).
  7. // The old format (GEO-132) will not work.
  8. include("geoipcity.inc");
  9. include("geoipregionvars.php");
  10. // uncomment for Shared Memory support
  11. // geoip_load_shared_mem("/usr/local/share/GeoIP/GeoIPCity.dat");
  12. // $gi = geoip_open("/usr/local/share/GeoIP/GeoIPCity.dat",GEOIP_SHARED_MEMORY);
  13. $gi = geoip_open("/usr/local/share/GeoIP/GeoIPCity.dat",GEOIP_STANDARD);
  14. $record = geoip_record_by_addr($gi,"24.24.24.24");
  15. print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n";
  16. print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
  17. print $record->city . "\n";
  18. print $record->postal_code . "\n";
  19. print $record->latitude . "\n";
  20. print $record->longitude . "\n";
  21. print $record->metro_code . "\n";
  22. print $record->area_code . "\n";
  23. geoip_close($gi);
  24. ?>