定制 ipwho/ipwho-ip-geolocation-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ipwho/ipwho-ip-geolocation-api

Composer 安装命令:

composer require ipwho/ipwho-ip-geolocation-api

包简介

The official PHP SDK for the IPWho IP Geolocation API by ipwho.org - Get detailed IP geolocation, timezone, connection, and security information with full type safety.

README 文档

README

The official PHP SDK for the IPWho IP Geolocation API by ipwho.org - Get detailed IP geolocation, timezone, connection, and security information with full type safety.

Installation

Install via Composer:

composer install

Or add to your composer.json:

{
  "require": {
    "ipwho/sdk-ipwho-php": "^1.0"
  }
}

Then run:

composer install

Quick Start

<?php

require 'vendor/autoload.php';

use SDKIpWho\Client;

$client = new Client('your-api-key');

// Get caller's location (uses your IP by default)
$location = $client->getLocation();
print_r($location);

// Get location for a specific IP
$specificLocation = $client->getLocation('8.8.8.8');
print_r($specificLocation);

Authentication

Initialize the client with your API key:

$client = new Client('your-api-key');

Get your API key by signing up here.

The SDK automatically includes your API key in the X-API-Key header for all requests. Missing API keys will throw an error immediately.

Methods

All methods accept an optional ip parameter. When omitted, the SDK uses the caller's IP address (calls /me endpoint). When provided, it queries the specific IP (calls /ip/{ip} endpoint).

getLocation(?string $ip = null): ?GeoLocation

Get geographical location data for an IP address.

Parameters:

  • $ip (optional) - IP address to query. Defaults to caller's IP if omitted.

Returns: GeoLocation object or null if unavailable.

Example:

// Get your own location
$myLocation = $client->getLocation();

// Get location for specific IP
$location = $client->getLocation('1.1.1.1');

print_r($location);
// GeoLocation {
//   continent: "Oceania",
//   continentCode: "OC",
//   country: "Australia",
//   countryCode: "AU",
//   capital: "Canberra",
//   region: "Queensland",
//   regionCode: "QLD",
//   city: "South Brisbane",
//   postalCode: "4101",
//   dialCode: "+61",
//   isInEu: false,
//   latitude: -27.4766,
//   longitude: 153.0166,
//   accuracyRadius: 500
// }

getTimezone(?string $ip = null): ?Timezone

Get timezone information for an IP address.

Parameters:

  • $ip (optional) - IP address to query. Defaults to caller's IP if omitted.

Returns: Timezone object or null if unavailable.

Example:

// Get your own timezone
$myTimezone = $client->getTimezone();

// Get timezone for specific IP
$timezone = $client->getTimezone('8.8.8.8');

print_r($timezone);
// Timezone {
//   timeZone: "America/Los_Angeles",
//   abbr: "PST",
//   offset: -28800,
//   isDst: false,
//   utc: "-08:00",
//   currentTime: "2026-02-07T10:30:00-08:00"
// }

getConnection(?string $ip = null): ?Connection

Get ISP and network connection details for an IP address.

Parameters:

  • $ip (optional) - IP address to query. Defaults to caller's IP if omitted.

Returns: Connection object or null if unavailable.

Example:

// Get your own connection details
$myConnection = $client->getConnection();

// Get connection details for specific IP
$connection = $client->getConnection('1.1.1.1');

print_r($connection);
// Connection {
//   asnNumber: 13335,
//   asnOrg: "Cloudflare, Inc.",
//   isp: "Cloudflare",
//   org: "APNIC Research and Development",
//   domain: "cloudflare.com",
//   connectionType: "Data Center/Web Hosting/Transit"
// }

getSecurity(?string $ip = null): ?Security

Get security information including VPN, Tor, and threat detection.

Parameters:

  • $ip (optional) - IP address to query. Defaults to caller's IP if omitted.

Returns: Security object or null if unavailable.

Example:

// Check your own IP security status
$mySecurity = $client->getSecurity();

// Check security for specific IP
$security = $client->getSecurity('8.8.8.8');

print_r($security);
// Security {
//   isVpn: false,
//   isTor: false,
//   isThreat: "low"
// }

getMe(): IPWhoData

Get complete IP information for the caller's IP address.

Returns: Full IPWhoData object with all available information.

Example:

$myData = $client->getMe();

print_r($myData);
// IPWhoData {
//   ip: "203.0.113.1",
//   geoLocation: { ... },
//   timezone: { ... },
//   flag: { ... },
//   currency: { ... },
//   connection: { ... },
//   security: { ... },
//   userAgent: { ... }
// }

getIp(string $ip): IPWhoData

Get complete IP information for a specific IP address.

Parameters:

  • $ip (required) - IP address to query.

Returns: Full IPWhoData object with all available information.

Example:

$data = $client->getIp('8.8.8.8');

print_r($data);
// IPWhoData {
//   ip: "8.8.8.8",
//   geoLocation: { ... },
//   timezone: { ... },
//   flag: { ... },
//   currency: { ... },
//   connection: { ... },
//   security: { ... }
// }

Type Classes

The SDK provides full type classes for all responses:

GeoLocation

{
    continent: string;           // Continent name
    continentCode: string;       // Continent code
    country: string;             // Country name
    countryCode: string;         // ISO 3166-1 alpha-2 country code
    capital: ?string;            // Capital city name
    region: ?string;             // Region name
    regionCode: ?string;         // Region code
    city: ?string;               // City name
    postalCode: ?string;         // Postal code
    dialCode: ?string;           // International dial code
    isInEu: ?bool;               // Is in European Union
    latitude: ?float;            // Latitude coordinate
    longitude: ?float;           // Longitude coordinate
    accuracyRadius: ?int;        // Accuracy radius in kilometers
}

Timezone

{
    timeZone: string;            // IANA timezone identifier
    abbr: ?string;               // Timezone abbreviation
    offset: ?int;                // UTC offset in seconds
    isDst: ?bool;                // Is in daylight saving time
    utc: ?string;                // UTC offset string
    currentTime: ?string;        // Current time in ISO 8601 format
}

Connection

{
    asnNumber: ?int;                // Autonomous System Number
    asnOrg: ?string;                // ASN organization name
    isp: ?string;                   // Internet Service Provider
    org: ?string;                   // Organization name
    domain: ?string;                // Domain name
    connectionType: ?string;        // Connection type description
}

Security

{
    isVpn: ?bool;              // Whether IP is using VPN
    isTor: ?bool;              // Whether IP is Tor exit node
    isThreat: ?string;         // Threat level: "low", "medium", "high"
}

Currency

{
    code: string;              // Currency code (ISO 4217)
    symbol: string;            // Currency symbol
    name: string;              // Currency name
    namePlural: ?string;       // Plural form of currency name
    hexUnicode: ?string;       // Hex unicode for symbol
}

Flag

{
    flagIcon: string;          // URL to flag icon
    flagUnicode: string;       // Unicode flag emoji
}

UserAgent

{
    browser: BrowserInfo;      // Browser information
    engine: EngineInfo;        // Engine information
    os: OSInfo;                // Operating system information
    device: DeviceInfo;        // Device information
    cpu: CPUInfo;              // CPU information
}

IPWhoData

Full response object containing all available data:

{
    ip: string;                // IP address
    geoLocation: ?GeoLocation; // Geolocation information
    timezone: ?Timezone;       // Timezone information
    flag: ?Flag;               // Flag information
    currency: ?Currency;       // Currency information
    connection: ?Connection;   // Connection information
    userAgent: ?UserAgent;     // User agent information (if available)
    security: ?Security;       // Security information
}

Error Handling

The SDK throws exceptions for:

  • Missing API key during initialization
  • Failed API requests
  • Invalid API responses

Example:

try {
    $client = new Client('your-api-key');
    $location = $client->getLocation('8.8.8.8');
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

For issues, feature requests, or questions, please visit:

ipwho/ipwho-ip-geolocation-api 适用场景与选型建议

ipwho/ipwho-ip-geolocation-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 88 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「security」 「sdk」 「location」 「timezone」 「ip-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ipwho/ipwho-ip-geolocation-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ipwho/ipwho-ip-geolocation-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 ipwho/ipwho-ip-geolocation-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-11