使用GeoIP获取IP地址对应的信息(安装)

GeoIP是MaxMind公司推出的一款可以查询IP地址对应详细信息的工具(包括国家城市邮编等,邮编中国的不一定有),其实是一个.mmdb .CSV的数据库文件,有免费版和付费版,信息精度不一样,网上还有一种简单的.dat文件的方法,但是只能查英文(看文件大小就知道少),所以想要很好的使用这个工具还是正儿八经的用composer安装吧。
URL:http://maxmind.github.io/GeoIP2-php/
另外提一句,.dat文件的那个弄好了之后可以做为php扩展使用,直接调用相关的函数即可。
先安装composer(不多提了),然后官方用的是这条命令:

php composer.phar require geoip2/geoip2:~2.0
//composer嘛,凡事先更新
$ sudo composer self-update
[sudo] password for tianyi: 
Updating to version 1.4.1 (stable channel).
    Downloading: 100%         
Use composer self-update --rollback to return to version 1.3.2
//请忽略目录,composer设置全局了之后哪里都能用
$ composer require
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Search for a package: geoip2    //这里输入geoip2

Found 15 packages matching geoip2

   [0] geoip2/geoip2
   [1] bonvga/geoip2
   [2] gpslab/geoip2
   [3] tobai/magento2-geo-ip2
   [4] overals/yii2-geoip2
   [5] bobey/geoip2-geolite2-composer
   [6] acidreign/laravel-geoip2
   [7] phirational/laravel-geoip2
   [8] marketo/silverstripe-regional-maxmind-geoip2
   [9] maxmind-db/reader
  [10] cravler/maxmind-geoip-bundle
  [11] mi-la01/kt_maxmind_geoip
  [12] lysenkobv/yii2-geoip
  [13] whitworf/geoip2-bundle
  [14] faustbrian/laravel-geoip2
//选第一个,当然这两条命令你也可以一起打
Enter package # to add, or the complete package name if it is not listed: 0
//选2.0版本或别的,注意,不填版本号直接enter的可能会卡在那没反应
Enter the version constraint to require (or leave blank to use the latest version): ~2.0
Search for a package: 
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
  - Installing composer/ca-bundle (1.0.7): Downloading (100%)         
  - Installing maxmind/web-service-common (v0.3.1): Downloading (100%)         
  - Installing maxmind-db/reader (v1.1.3): Downloading (100%)         
  - Installing geoip2/geoip2 (v2.4.5): Downloading (100%)         
composer/ca-bundle suggests installing symfony/process (This is necessary to reliably check whether openssl_x509_parse is vulnerable on older php versions, but can be ignored on PHP 5.5.6+)
maxmind-db/reader suggests installing ext-maxminddb (A C-based database decoder that provides significantly faster lookups)
Writing lock file
Generating autoload files
//安装完成

你可能感兴趣的:(PHP)