Code Monkey home page Code Monkey logo

ip2location / ip2location-codeigniter4 Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 646 KB

IP2Location library for CodeIgniter 4. Use IP2Location geolocation database to lookup the 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 that any IP address or hostname originates from.

Home Page: https://www.ip2location.com

License: MIT License

PHP 100.00%
geolocation ip-lookup ip-geolocation ip-database ip-address-database ip2location-bin-database geolocation-information codeigniter-ip2location

ip2location-codeigniter4's Introduction

IP2Location CodeIgniter 4 Library

This module enables users to retrieve below geolocation information from an IP address. It supports both the IPv4 and IPv6 address.

  • Country
  • Region
  • City
  • Latitude & Longitude
  • ZIP Code
  • Time Zone
  • Area Code
  • Net Speed
  • ISP
  • Domain
  • Mobile Information
  • Weather Station Information
  • Elevation
  • Usage Type
  • Address Type
  • Category

This library will only work with CodeIgniter 4. For CodeIgniter 3, you can get it from here.

Installation

Upload Controllers, Libraries and Models to CodeIgniter app folder.

Usage

This module is able to query the IP address information from either BIN database or web service. This section will explain how to use this extension to query from BIN database and web service.

Sample codes are given in this project, under Controllers folder. After added the following line into the app\Config\Routes.php file, you may run the sample code by using <your_domain>/index.php/ip2location_test.

$routes->get('ip2location_test', 'IP2Location_test::index');

BIN Database

Use following codes in your application for get geolocation information.

    // (optional) Define IP2Location database path. By default, the IP2LOCATION_DATABASE is pointed to *app/Libraries/IP2Location/IP2LOCATION-DB.BIN* if you choose not to change the original settings.
    define('IP2LOCATION_DATABASE', '/path/to/ip2location/database');

    $ipl = new IP2Location_lib();
    $countryCode = $ipl->getCountryCode('8.8.8.8');

Below are the methods supported for BIN data file lookup.

    $countryCode = $ipl->getCountryCode($ip);
    $countryName = $ipl->getCountryName($ip);
    $regionName = $ipl->getRegionName($ip);
    $cityName = $ipl->getCityName($ip);
    $latitude = $ipl->getLatitude($ip);
    $longitude = $ipl->getLongitude($ip);
    $isp = $ipl->getISP($ip);
    $domainName = $ipl->getDomainName($ip);
    $zipCode = $ipl->getZIPCode($ip);
    $timeZone = $ipl->getTimeZone($ip);
    $netSpeed = $ipl->getNetSpeed($ip);
    $iddCode = $ipl->getIDDCode($ip);
    $areaCode = $ipl->getAreaCode($ip);
    $weatherStationCode = $ipl->getWeatherStationCode($ip);
    $weatherStationName = $ipl->getWeatherStationName($ip);
    $mcc = $ipl->getMCC($ip);
    $mnc = $ipl->getMNC($ip);
    $mobileCarrierName = $ipl->getMobileCarrierName($ip);
    $elevation = $ipl->getElevation($ip);
    $usageType = $ipl->getUsageType($ip);
    $addressType = $ipl->getAddressType($ip);
    $category = $ipl->getCategory($ip);

Web Service

Use following codes in your application for get geolocation information.

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

    // (required) Define IP2Location Web service package of different granularity of return information.
    define('IP2LOCATION_PACKAGE', 'WS1');

    // (optional) Define to use https or http.
    define('IP2LOCATION_USESSL', false);

    // (optional) Define extra information in addition to the above-selected package. Refer to https://www.ip2location.com/web-service/ip2location for the list of available addons.
    define('IP2LOCATION_ADDONS', []);

    // (optional) Define Translation information. Refer to https://www.ip2location.com/web-service/ip2location for available languages.
    define('IP2LOCATION_LANGUAGE', 'zh-cn');

    $ipl = new IP2Location_lib();
    print_r ($ipl->getWebService('8.8.8.8'));

To use IP2Location.io API for getting the geolocation information, you can use the following code to do so:

	// (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', 'zh-cn');

    $ipl = new IP2Location_lib();
    print_r ($ipl->getWebService('8.8.8.8'));

MySQL Query

Use following codes in your application for get geolocation information.

    define('IP2LOCATION_DATABASE_TABLE', 'ip2location_table_name');

    $db = model('IP2Location_model', false);
    print_r ($db->lookup('8.8.8.8'));

IPTools

Use following codes in your application for get IPTools class information.

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

Dependencies

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

An outdated BIN database was provided in this release for your testing. You are recommended to visit the above links to download the latest BIN database.

For the BIN database update, you can just rename the downloaded BIN database to IP2LOCATION-DB.BIN and replace the copy in app/Libraries/IP2Location/ (if you didn't change the default IP2LOCATION_DATABASE constant as described in the Usage section).

You can also sign up for IP2Location Web Service or 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: [email protected]

Website: https://www.ip2location.com

ip2location-codeigniter4's People

Contributors

ip2location avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.