djonepl/ipapi-co-php

使用PHP的ip-api.com简单API

1.0.1 2024-02-12 20:31 UTC

This package is auto-updated.

Last update: 2024-09-12 22:11:14 UTC


README

使用PHP的ipapi.co简单API

安装

仅使用composer要求该包。

composer require djonepl/ipapi-co-php

使用该包

只需导入、实例化和调用

<?php

use IpApi\IpApi;

$api = new IpApi('APIKEY');
$location = $api->lookup('IP');

\IpApi\Location对象

位置对象默认返回由以下字段组成的模式

ip 网络版本 城市 地区 地区代码 国家 国家名称 国家代码 国家代码_iso3 国家首都 国家顶级域名 大洲代码 在欧盟 邮编 纬度 经度 时区 utc_offset 国家电话代码 货币 货币名称 语言 国家面积 国家人口 asn 组织

位置对象还有一些其他方法和功能

$location = $api->lookup('8.8.8.8');

// Convert the object to an array
$data = $location->toArray();

// Extract city and ASN 
echo $location->city; // Mountain View
echo $location->asn; // AS15169