PHP code example of magefan / module-geoip

1. Go to this page and download the library: Download magefan/module-geoip 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/ */

    

magefan / module-geoip example snippets


composer magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy

protected $ipToCountryRepository;

public function __construct(
    \Magefan\GeoIp\Model\IpToCountryRepository $ipToCountryRepository,
    ....//other code
) {
    $this->ipToCountryRepository = $ipToCountryRepository;
    ...//other code
}

public function example() {
    $visitorCountyCode = $this->ipToCountryRepository->getVisitorCountryCode();
    $someCountryCodeByIp = $this->ipToCountryRepository->getCountryCode('104.27.164.57');
    ...//other code
}