sample_city.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. define("DIR_LOCALISE", getcwd() . "/");
  14. $gi = geoip_open(DIR_LOCALISE."GeoLiteCity.dat",GEOIP_STANDARD);
  15. $record = geoip_record_by_addr($gi,"93.17.95.144");
  16. print '<?xml version="1.0" encoding="UTF-8"?>';
  17. print "<root>";
  18. print "<continent_code>" . $record->continent_code . "</continent_code>";
  19. print "<country_code>" . $record->country_code . "</country_code>";
  20. print "<country_code3>" . $record->country_code3 . "</country_code3>";
  21. print "<country_name>" . $record->country_name . "</country_name>";
  22. print "<region>" . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "</region>";
  23. print "<city>" . $record->city . "</city>";
  24. print "<postal_code>" . $record->postal_code . "</postal_code>";
  25. print "<latitude>" . $record->latitude . "</latitude>";
  26. print "<longitude>" . $record->longitude . "</longitude>";
  27. print "<dma_code>" . $record->dma_code . "</dma_code>";
  28. print "<area_code>" . $record->area_code . "</area_code>";
  29. print "</root>";
  30. geoip_close($gi);
  31. ?>