使用 IP 地址的简单地理位置信息

1.5.2 2016-04-12 03:58 UTC

This package is not auto-updated.

Last update: 2024-09-13 12:21:10 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Geo Ip 使用 GeoPlugin 的数据从 IP 地址获取所有可用信息。

与 Laravel 5.5 (已测试) 兼容。

Geo IP 使用 Geoplugin 收集信息。

安装

您可以通过 composer 安装 GeoIp。

$ composer require sabartampubolon/geoip

需要 Laravel 框架 5.5 和 PHP 5.5.9 或更高版本。访问 GeoIp 仓库在 Packagist

使用方法

要使用 GeoIp,您可以将 GeoIp 实例注入到 Laravel 控制器中

<?php

use Sabartampubolon\Geoip\Geoip;

// Use destination Ip
$geoip = new Geoip('8.8.8.8');
 
// Or just let it blank to automatic use client ip address
$geoip = new Geoip();
 
  
// Gather information from ip address
$info = $geoip->getInfo();

上述代码将以 json 格式给出结果(使用 IP 地址 8.8.8.8)

{"ip_address":"8.8.8.8","country_code":"US","country_name":"United States","city":"Mountain View","region":"CA","region_name":"California","region_code":"CA","latitude":"37.3845","longitude":"-122.0881"}

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件