PHP code example of ip2location / ip2location-codeigniter4
1. Go to this page and download the library: Download ip2location/ip2location-codeigniter4 library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ip2location / ip2location-codeigniter4 example snippets
// (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');
// (ine('IP2LOCATION_API_KEY', 'your_api_key');
// ( 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'));
// (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'));