ip2location/ip2location-cakephp 问题修复 & 功能扩展

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

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

ip2location/ip2location-cakephp

Composer 安装命令:

composer require ip2location/ip2location-cakephp

包简介

Lookup for visitor's IP information, such as country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type.

README 文档

README

Latest Stable Version Total Downloads

IP2Location CakePHP plugin enables the user to find the country, region, district, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type, IP address type, IAB advertising category and ASN from IP address using IP2Location database. It has been optimized for speed and memory utilization. Developers can use the API to query all IP2Location BIN databases or web service for applications written using CakePHP.

Note: This plugin works in CakePHP 4 and CakePHP 5.

INSTALLATION

  1. Run the command: composer require ip2location/ip2location-cakephp to download the plugin into the CakePHP platform.
  2. Download latest IP2Location BIN database
  3. Unzip and copy the BIN file into /vendor/ip2location/ip2location-cakephp/src/Data folder.
  4. Rename the BIN file to IP2LOCATION.BIN.

Note: The plugin has included an old BIN database for your testing and development purpose. You may want to download a latest copy of BIN database as the URL stated above. The BIN database refers to the binary file ended with .BIN extension, but not the CSV format. Please select the right package for download.

USAGE

In this tutorial, we will show you on how to create a TestsController to display the IP information.

  1. Create a TestsController in CakePHP using the below command line
php bin/cake bake controller Tests
  1. Create a Tests folder in /cakephp/templates if not exists.
  2. Create an empty index.php file in /cakephp/templates/Tests folder.
  3. Open the cakephp/src/Controller/TestsController.php in any text editor.
  4. Remove the contents in TestsController.php and add the below lines into the controller file.

Note: You just need to load the IP2Location library with use IP2LocationCakePHP\Controller\IP2LocationCoresController to use the functions.

<?php
namespace App\Controller;

use App\Controller\AppController;
use IP2LocationCakePHP\Controller\IP2LocationCoresController;

// (required) Define IP2Location.io API key.
define('IP2LOCATION_IO_API_KEY', 'your_api_key');

// (optional) Define Translation information. Refer to https://www.ip2location.io/ip2location-documentation for available languages.
define('IP2LOCATION_IO_LANGUAGE', 'en');

/**
 * Tests Controller
 */
class TestsController extends AppController
{

    /**
     * Index method
     *
     * @return \Cake\Http\Response|void
     */
    public function index()
    {
        $IP2Location = new IP2LocationCoresController();

        $record = $IP2Location->get('8.8.8.8');
        echo 'Result from BIN Database:<br>';
        echo 'IP Address: ' . $record['ipAddress'] . '<br>';
        echo 'IP Number: ' . $record['ipNumber'] . '<br>';
        echo 'ISO Country Code: ' . $record['countryCode'] . '<br>';
        echo 'Country Name: ' . $record['countryName'] . '<br>';
        echo 'Region Name: ' . $record['regionName'] . '<br>';
        echo 'City Name: ' . $record['cityName'] . '<br>';
        echo 'Latitude: ' . $record['latitude'] . '<br>';
        echo 'Longitude: ' . $record['longitude'] . '<br>';
        echo 'ZIP Code: ' . $record['zipCode'] . '<br>';
        echo 'Time Zone: ' . $record['timeZone'] . '<br>';
        echo 'ISP Name: ' . $record['isp'] . '<br>';
        echo 'Domain Name: ' . $record['domainName'] . '<br>';
        echo 'Net Speed: ' . $record['netSpeed'] . '<br>';
        echo 'IDD Code: ' . $record['iddCode'] . '<br>';
        echo 'Area Code: ' . $record['areaCode'] . '<br>';
        echo 'Weather Station Code: ' . $record['weatherStationCode'] . '<br>';
        echo 'Weather Station Name: ' . $record['weatherStationName'] . '<br>';
        echo 'MCC: ' . $record['mcc'] . '<br>';
        echo 'MNC: ' . $record['mnc'] . '<br>';
        echo 'Mobile Carrier Name: ' . $record['mobileCarrierName'] . '<br>';
        echo 'Elevation: ' . $record['elevation'] . '<br>';
        echo 'Usage Type: ' . $record['usageType'] . '<br>';
        echo 'Address Type: ' . $record['addressType'] . '<br>';
        echo 'Category: ' . $record['category'] . '<br>';
        echo 'District: ' . $record['district'] . '<br>';
        echo 'ASN: ' . $record['asn'] . '<br>';
        echo 'AS: ' . $record['as'] . '<br>';

        $record = $IP2Location->getWebService('8.8.8.8');
        echo 'Result from Web service:<br>';
        echo '<pre>';
        print_r ($record);
        echo '</pre>';

        var_dump($IP2Location->isIpv4('8.8.8.8'));echo '<br>';
        var_dump($IP2Location->isIpv6('2001:4860:4860::8888'));echo '<br>';
        print_r($IP2Location->ipv4ToDecimal('8.8.8.8'));echo '<br>';
        print_r($IP2Location->decimalToIpv4(134744072));echo '<br>';
        print_r($IP2Location->ipv6ToDecimal('2001:4860:4860::8888'));echo '<br>';
        print_r($IP2Location->decimalToIpv6('42541956123769884636017138956568135816'));echo '<br>';
        print_r($IP2Location->ipv4ToCidr('8.0.0.0', '8.255.255.255'));echo '<br>';
        print_r($IP2Location->cidrToIpv4('8.0.0.0/8'));echo '<br>';
        print_r($IP2Location->ipv6ToCidr('2002:0000:0000:1234:abcd:ffff:c0a8:0000', '2002:0000:0000:1234:ffff:ffff:ffff:ffff'));echo '<br>';
        print_r($IP2Location->cidrToIpv6('2002::1234:abcd:ffff:c0a8:101/64'));echo '<br>';
        print_r($IP2Location->compressIpv6('2002:0000:0000:1234:FFFF:FFFF:FFFF:FFFF'));echo '<br>';
        print_r($IP2Location->expandIpv6('2002::1234:FFFF:FFFF:FFFF:FFFF'));echo '<br>';
    }

}
  1. Enter the URL /Tests and run. You should see the information of 8.8.8.8 IP address.

DEPENDENCIES

This library requires IP2Location BIN data file or IP2Location API key to function. You may download the BIN data file at

You can also sign up for IP2Location.io IP Geolocation API to get one free API key.

IPv4 BIN vs IPv6 BIN

Use the IPv4 BIN file if you just need to query IPv4 addresses.

Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

SUPPORT

Email: support@ip2location.com

Website: https://www.ip2location.com

ip2location/ip2location-cakephp 适用场景与选型建议

ip2location/ip2location-cakephp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.66k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2017 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 21
  • Watchers: 7
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-13