1. Go to this page and download the library: Download tantacula/ip2country 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/ */
// Returns the 2 letter country code for the user, eg: 'US'
$myCountryCode = Ip2Country::get();
// Returns the full name of the country, eg: 'United States'
$myCountryName = Ip2Country::getFull();
// Get the country for someone other than user on the page
$someonesIpAddress = '192.168.0.1';
$someonesCountryCode = Ip2Country::get($someonesIpAddress);
return array(
// If IP address is not found, what country is returned
'default_country_code' => 'US',
'default_country_name' => 'United States',
// Since our data will change, at most, once a month. Cache the Ip lookup for a day
// Default: 1 day. Set to 0 or null to disable.
'cache_results' => 60 * 24
);