PHP code example of gai871013 / ip-location

1. Go to this page and download the library: Download gai871013/ip-location library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gai871013 / ip-location example snippets



['providers' => [
    // ...
    Gai871013\IpLocation\ServiceProvider::class,
],
'aliases' => [
    // ...
    'IpLocation' => Gai871013\IpLocation\Facades\IpLocation::class,
],
];


use Gai871013\IpLocation\Facades\IpLocation;

    // ...
    dump(app('IpLocation')->getLocation('www.wc87.com'));
    dd(IpLocation::getLocation('8.8.4.4'));
    array(
      "ip" => "101.200.45.167",
      "beginip" => "101.200.0.0",
      "endip" => "101.201.255.255",
      "country" => "北京市",
      "area" => "阿里云BGP数据中心",
    );

    array(
      "ip" => "8.8.4.4",
      "beginip" => "8.8.4.4",
      "endip" => "8.8.4.4",
      "country" => "美国",
      "area" => "加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器",
    );
    // ...



use Gai871013\IpLocation\IpLocation;

$ipLocation = new IpLocation();

// url
$url = 'https://www.baidu.com';
$ip = '127.0.0.1';
// 使用域名国家&运营商
$result = $ipLocation->getLocation($url);
dump($result);

array(
  "ip" => "61.135.169.125",
  "beginip" => "61.135.169.0",
  "endip" => "61.135.169.255",
  "country" => "北京市",
  "area" => "北京百度网讯科技有限公司联通节点",
);

// 使用IP地址国家&运营商
$result = $ipLocation->getLocation($ip);
dump($result);

array(
  "ip" => "127.0.0.1",
  "beginip" => "127.0.0.1",
  "endip" => "127.0.0.1",
  "country" => "本机地址",
  "area" => "",
)


# ipip
$path = 'path-to-ipdb.ipdb' || null;

$city = new Gai871013\IpLocation\ipip\db\City($path);
var_dump($city->find('118.28.1.1'));
var_dump($city->find('8.8.8.8'));
var_dump($city->find('127.0.0.1'));