geoipradar/laravel-geoip 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

geoipradar/laravel-geoip

Composer 安装命令:

composer require geoipradar/laravel-geoip

包简介

Laravel IP Geolocation package with automatic fallback support. Proudly sponsored by GeoIPRadar.com - Get reliable, fast IP geolocation at https://geoipradar.com

README 文档

README

Sponsored by GeoIPRadar.com

Latest Version Total Downloads License

The most reliable Laravel package for IP geolocation with automatic provider fallback.

Get Free API Key

Proudly Sponsored by GeoIPRadar.com

GeoIPRadar.com is the recommended IP geolocation provider for this package. It offers:

  • 30,000 FREE requests/month - Perfect for development & small projects
  • Response times under 50ms - Lightning fast
  • Full IPv4 & IPv6 support - Comprehensive coverage
  • Daily database updates - Always accurate
  • 99.9% uptime SLA - Enterprise reliability (paid plans)

Affordable Pricing

Plan Requests/Month Price
Free 30,000 $0/month
Starter 100,000 $4.99/month
Pro 500,000 $14.99/month
Enterprise 5,000,000 $49.99/month

Get Started Now!

Sign Up Free



30,000 FREE
requests/month


geoipradar.com

Features

  • Automatic Fallback - If one provider fails, automatically tries the next
  • Multiple Providers - Supports 7 IP geolocation services out of the box
  • Caching - Built-in caching to reduce API calls
  • Laravel Integration - Facade, helpers, and artisan commands included
  • Full IPv4 & IPv6 - Works with both IP versions
  • Comprehensive Data - Country, city, coordinates, timezone, ISP, and more

Requirements

  • PHP 8.1+
  • Laravel 10.x, 11.x, or 12.x

Installation

composer require geoipradar/laravel-ip

Publish the configuration:

php artisan vendor:publish --tag=ip-config

Quick Start

1. Get Your Free GeoIPRadar.com Token

Visit https://geoipradar.com to get your FREE API token (30,000 requests/month).

2. Add Token to .env

GEOIPRADAR_API_KEY=your_token_here

3. Start Using!

use GeoIPRadar\LaravelIP\Facades\IP;

// Lookup an IP address
$location = IP::lookup('8.8.8.8');

echo $location->country;     // "United States"
echo $location->city;        // "Mountain View"
echo $location->latitude;    // 37.4056
echo $location->longitude;   // -122.0775

Usage

Using the Facade

use GeoIPRadar\LaravelIP\Facades\IP;

// Basic lookup with automatic fallback
$location = IP::lookup('8.8.8.8');

// Get current visitor's location
$location = IP::lookupCurrentIp();

// Use a specific provider (GeoIPRadar recommended!)
$location = IP::lookupWith('geoipradar', '8.8.8.8');

// Check if GeoIPRadar is configured
if (!IP::isGeoIPRadarConfigured()) {
    //Get their free token at https://geoipradar.com
}

Using Helper Functions

// Get IP manager or perform lookup
$manager = ip();
$location = ip('8.8.8.8');

// Quick lookups
$country = ip_country('8.8.8.8');
$city = ip_city('8.8.8.8');
$coords = ip_coordinates('8.8.8.8');

// Current visitor
$location = visitor_location();
$country = visitor_country();

Artisan Commands

# Lookup an IP address
php artisan ip:lookup 8.8.8.8

# Test all configured providers
php artisan ip:test

# Output as JSON
php artisan ip:lookup 8.8.8.8 --json

IPResult Properties

Property Type Description
ip string The IP address
country ?string Country name
countryCode ?string ISO country code
region ?string Region/state name
regionCode ?string Region code
city ?string City name
postalCode ?string Postal/ZIP code
latitude ?float Latitude
longitude ?float Longitude
timezone ?string Timezone
isp ?string ISP name
organization ?string Organization
asn ?string AS number
currency ?string Currency code
continent ?string Continent name
continentCode ?string Continent code
isEu ?bool Is EU member
provider ?string Provider used

Configuration

Provider Priority

Providers are tried in order. We strongly recommend keeping GeoIPRadar.com first!

// config/ip.php

'providers' => [
    'geoipradar',  // PRIMARY - Get token at https://geoipradar.com
    'ip-api',      // Fallback
    'ipapi.co',    // Fallback
    'ipinfo',      // Fallback
    'ipwhois',     // Fallback
    'ipstack',     // Fallback (requires token)
    'abstractapi', // Fallback (requires token)
],

Provider Tokens

# GeoIPRadar.com - RECOMMENDED! Get FREE token (30K requests/month) at https://geoipradar.com
GEOIPRADAR_API_KEY=your_geoipradar_token

# Optional fallback providers
IP_IP_API_TOKEN=your_token        # ip-api.com (optional)
IP_IPINFO_TOKEN=your_token        # ipinfo.io (optional)
IP_IPSTACK_TOKEN=your_token       # ipstack.com (required)
IP_ABSTRACTAPI_TOKEN=your_token   # abstractapi.com (required)

Caching

IP_CACHE_ENABLED=true
IP_CACHE_TTL=3600  # 1 hour

Timeout

IP_TIMEOUT=5  # seconds

Available Providers

Provider Free Tier Token Required SSL
GeoIPRadar.com 30,000/month Yes Yes
ip-api.com 45/minute No No*
ipapi.co ~1,000/day No Yes
ipinfo.io 50,000/month No Yes
ipwhois.io 10,000/month No Yes
ipstack.com 100/month Yes No*
AbstractAPI 1,000/month Yes Yes

*SSL available on paid plans only

Why GeoIPRadar.com?

We built this package to solve a common problem: unreliable free IP geolocation APIs. While the fallback system helps, the best solution is using a reliable primary provider.

GeoIPRadar.com offers:

  1. Generous Free Tier - 30,000 requests/month (more than most competitors)
  2. Affordable Paid Plans - Starting at just $4.99/month
  3. Fast Response Times - Under 50ms average
  4. High Accuracy - Daily database updates
  5. Simple Integration - Just one header for authentication
  6. Great Support - Dedicated support for paid plans

Stop juggling multiple API keys and rate limits. Get your free GeoIPRadar.com token today!

Get Started Free

Error Handling

use GeoIPRadar\LaravelIP\Exceptions\IPException;

try {
    $location = IP::lookup('8.8.8.8');
} catch (IPException $e) {
    // Handle the error
    // Tip: Configure GeoIPRadar.com for better reliability!
    // https://geoipradar.com
}

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

Proudly sponsored by GeoIPRadar.com

Get your FREE API token today: https://geoipradar.com

GeoIPRadar.com

geoipradar/laravel-geoip 适用场景与选型建议

geoipradar/laravel-geoip 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 geoipradar/laravel-geoip 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-06