承接 playtini/geoip 相关项目开发

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

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

playtini/geoip

Composer 安装命令:

composer require playtini/geoip

包简介

Simple GeoIP Client for MaxMind and IP2Location Databases

README 文档

README

Maintainer

This library is created and supported by Playtini.

We're hiring marketers (FB, Tiktok, UAC, in-app, Google) and developers (PHP, JS): playtini.ua/jobs

Install

composer require playtini/geoip

Usage

See examples/*.php.

use Playtini\GeoIp\GeoIp;

require_once(__DIR__ . '/vendor/autoload.php');

$geoIp = new GeoIp();

echo $geoIp->country('8.8.8.8') . "\n"; // US

print_r($geoIp->city('190.0.0.1'));
/*
    [country] => CO
    [city] => Medellín
    [subdivision] => Antioquia
    [subdivision1] => Antioquia
    [subdivision2] =>
    [subdivision3] =>
    [subdivision_code] => ANT
    [postal] => 050021
    [accuracy_radius] => 10
    [latitude] => 6.2529
    [longitude] => -75.5646
    [timezone] => America/Bogota
 */

echo $geoIp->maxMindCountry('190.0.0.1') . "\n"; // CO

print_r($geoIp->maxMindCity('190.0.0.1'));
/*
    [country] => CO
    [city] => Medellín
    [subdivision] => Antioquia
    [subdivision1] => Antioquia
    [subdivision2] =>
    [subdivision3] =>
    [subdivision_code] => ANT
    [postal] => 050021
    [accuracy_radius] => 10
    [latitude] => 6.2529
    [longitude] => -75.5646
    [timezone] => America/Bogota
 */

print_r($geoIp->maxMindAsn('190.0.0.1'));
/*
    [org] => EPM Telecomunicaciones S.A. E.S.P.
    [num] => 13489
    [net] => 190.0.0.0/18
*/

echo $geoIp->ip2LocationCountry('190.0.0.1') . "\n"; // CO

echo $geoIp->ip2LocationProxyType('190.0.0.1') . "\n"; // -
echo $geoIp->ip2LocationProxyType('1.2.3.4') . "\n"; // VPN
echo $geoIp->ip2LocationProxyType('8.8.8.8') . "\n"; // DCH

If your GeoIP files aren't named by default or aren't in the dir /usr/share/GeoIP/ then pass arguments to constructors.

Priority

IP2Location database has priority for methods country, city:

  • country - if IP2Location data is not empty - don't look up MaxMind
  • city - if IP2Location country differs from MaxMind - use IP2Location country and empty city

If you have guesses which countries may IP be from then you can pass the second argument array $preferredCountries. Then even if IP2Location country differs from MaxMind but MaxMind returns country from preferred then MaxMind country will be used.

echo $geoIp->maxMindCountry('80.231.192.1') . "\n"; // CA
echo $geoIp->ip2LocationCountry('80.231.192.1') . "\n"; // DZ

echo $geoIp->country('80.231.192.1') . "\n"; // DZ - IP2Location has higher priority

echo $geoIp->country('80.231.192.1', ['BR', 'MX']) . "\n"; // DZ
// IP2Location still has higher priority, MaxMind country is not among preferred countries

echo $geoIp->country('80.231.192.1', ['CA', 'AU']) . "\n"; // CA
// MaxMind country is among preferred countries; it is used instead of different IP2Location country

Symfony

Add to config/services.yaml

imports:
    - { resource: '../vendor/playtini/geoip/config/config.yaml' }

You can copy config to your .yaml-files without import and tune for your needs.

Add env GEOIP_DIR with all your GeoIP database files. Default - %kernel.project_dir%/data/geoip

Use with autowire

/**
 * @Route("/test", name="test")
 */
public function test(GeoIp $geoIp): Response
{
    dd($geoIpParser->country('1.1.1.1'));
}

GeoIpExtension is optional to add but if you added it you have Twig filters:

  • domain_ip: convert domain name or IP to IP - 'google.com'|domain_ip, '1.1.1.1'|domain_ip
  • ip_country_code: convert IP to country code - '1.1.1.1'|ip_country_code - US, AU, ...
  • ip_flag: convert IP to HTML with flag - '1.1.1.1'|ip_flag
  • country_code_flag: convert country code to HTML with flag - 'CA'|country_code_flag

To use flags copy public/css/flags.css and public/img/flags.png to your public folder.

Add to base.html.twig or other template:

<link rel="stylesheet" href="{{ asset('css/flags.css') }}">

playtini/geoip 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2024-06-27