项目作者: mpdroog

项目描述 :
IP to country/city
高级语言: PHP
项目地址: git://github.com/mpdroog/ip2loc.git
创建时间: 2017-11-30T11:07:48Z
项目社区:https://github.com/mpdroog/ip2loc

开源协议:

下载


GeoIP lookup

Generic PHP-codebase to easily switch between MaxMind/IP2Location.

Lightweight codebase for MaxMind and IP2Location.

  • IP2Location without autoload/mysql (binfile)

Example

  1. <?php
  2. require "path/to/this/repo/index.php";
  3. echo "<pre>";
  4. $res = ip2loc($_SERVER["REMOTE_ADDR"]);
  5. var_dump($res);
  6. /*
  7. array(6) {
  8. ["ip"]=>
  9. string(14) "94.232.119.106"
  10. ["ipv"]=>
  11. int(4)
  12. ["iso2"]=>
  13. string(2) "SM"
  14. ["city"]=>
  15. string(10) "San Marino"
  16. ["lat"]=>
  17. float(43.933330535889)
  18. ["long"]=>
  19. float(12.449999809265)
  20. }
  21. */
  22. $res = maxmind($_SERVER["REMOTE_ADDR"]);
  23. var_dump($res);
  24. /*
  25. array(6) {
  26. ["ip"]=>
  27. string(14) "94.232.119.106"
  28. ["ipv"]=>
  29. int(4)
  30. ["iso2"]=>
  31. string(2) "SM"
  32. ["city"]=>
  33. NULL
  34. ["lat"]=>
  35. float(43.9333)
  36. ["long"]=>
  37. float(12.4667)
  38. }
  39. */

Install

  1. # TODO: Composer: https://getcomposer.org/download/
  2. mkdir -p /usr/local/share/GeoIP
  3. chown www-data:www-data /usr/local/share/GeoIP
  4. wget https://github.com/maxmind/GeoIP2-php/releases/download/v2.7.0/geoip2.phar
  5. ./composer.phar install
  6. # Fix permissions
  7. ./perm.sh
  8. vi /etc/cron.d/geoip
  9. ...
  10. @daily www-data /data01/xsnews/ip2loc/update.sh
  11. ...
  12. /etc/init.d/cron restart