承接 whois-api/simple-geoip 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

whois-api/simple-geoip

Composer 安装命令:

composer require whois-api/simple-geoip

包简介

The simplest possible way to get IP geolocation information.

README 文档

README

The simplest possible way to get IP geolocation information in PHP.

Prerequisites

To use this library, you'll need to create a free IP Geolocation account: https://ip-geolocation.whoisxmlapi.com/api

If you haven't done this yet, please do so now.

Installation

To install simple-geoip using composer, simply run:

$ composer require whois-api/simple-geoip

In the root of your project directory.

To use the library, use Composer's autoload

require_once __DIR__ . "/vendor/autoload.php";

Requirements

Supported PHP versions:

  • PHP 5.6.x
  • PHP 7.0.x
  • PHP 7.1.x
  • PHP 7.2.x

Dependencies:

  • mbstring
  • mbregex
  • json
  • curl

Documentation

Full API documentation available here

Usage

Once you have simple-geoip installed, you can use it to easily find the physical location of a given IP address.

This library gives you access to all sorts of geographical location data that you can use in your application in any number of ways.

<?php
require_once  __DIR__ . '/../vendor/autoload.php';

use WhoisApi\SimpleGeoip\Builders\ClientBuilder;


$builder = new ClientBuilder();

$client = $builder->build('your API_KEY');

try {
    echo $client->getRawData('8.8.8.8', 'json') . PHP_EOL;
    echo print_r($client->get('8.8.8.8'), 1) . PHP_EOL;
    
    $result = $client->get('1.1.1.1');
    echo 'IP: ' . $result->ip . PHP_EOL;
    echo 'Country: ' . $result->location->country . PHP_EOL;
    echo 'Region: ' . $result->location->region . PHP_EOL;
    echo 'City: ' . $result->location->city . PHP_EOL;
    echo 'Latitude: ' . $result->location->lat . PHP_EOL;
    echo 'Longitude: ' . $result->location->lng . PHP_EOL;
    echo 'Postal Code: ' . $result->location->postalCode . PHP_EOL;
    echo 'Timezone: ' . $result->location->timezone . PHP_EOL;
} catch (\Throwable $exception) {
    echo "Error: {$exception->getCode()} {$exception->getMessage()}" . PHP_EOL;
}

More examples you can see in the "examples" directory.

Here's the sort of data you might get back when performing a ip geolocation lookup request:

{
  "ip": "8.8.8.8",
  "location": {
    "country": "US",
    "region": "California",
    "city": "Mountain View",
    "lat": 37.40599,
    "lng": -122.078514,
    "postalCode": "94043",
    "timezone": "-08:00"
  }
}

Development

After you clone this repository you need to install all requirements:

$ composer install

To run tests you can use the following command

$ composer run-script test

统计信息

  • 总下载量: 649
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固