magefan / module-geoip
magefan/module-geoip
Allows to get country code by IP
Magento 2 GeoIP Database Extension by Magefan
This Magento 2 GeoIP module provides you PHP methods for getting customer country by IP, without any additional plugin for PHP.
It is used for Magento 2 Currency Auto Switcher and Magento 2 Auto Language Switcher by Magefan
🇺🇦 Stand with Ukraine! How can you help?
Requirements
- Magento Community Edition 2.0.x-2.4.x or Magento Enterprise Edition 2.0.x-2.4.x
Installation Method 1 - Installing via composer
- Open command line
- Using command "cd" navigate to your magento2 root directory
- Run command: composer require magefan/module-geoip
composer require magefan/module-geoip
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
Installation Method 2 - Installing using archive
- Install GeoIP2 PHP API (https://github.com/maxmind/GeoIP2-php).
- Download ZIP Archive
- Extract files
- In your Magento 2 root directory create folder app/code/Magefan/GeoIp
- Copy files and folders from archive to that folder
- In command line, using "cd", navigate to your Magento 2 root directory
- Run commands:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
How To Use
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
}
Support
If you have any issues, please contact us
then if you still need help, open a bug report in GitHub's
issue tracker.
Need More Features?
Please contact us to get a quote
https://magefan.com/contact
License
The code is licensed under Open Software License ("OSL") v. 3.0.
This product includes GeoLite2 data created by MaxMind, available from
https://www.maxmind.com.
Originally use these databases:
Magento 2 Extensions by Magefan
Magento 2 Google Extensions
- Magento 2 Google Indexing
- Magento 2 Google Analytics 4
- Magento 2 Google Tag Manager
- Magento 2 Google Shopping Feed
- Magento 2 Google Customer Reviews
Magento 2 SEO Extensions
- Magento 2 SEO Extension
- Magento 2 Rich Snippets
- Magento 2 HTML Sitemap
- Magento 2 XML Sitemap
- Magento 2 Facebook Open Graph
- Magento 2 Twitter Cards
Magento 2 Speed Optimization Extensions
- Magento 2 Google Page Speed Optimizer
- Magento 2 Full Page Cache Warmer
- Magento 2 Image Lazy Load
- Magento 2 WebP Images
- Magento 2 Rocket JavaScript
Magento 2 Admin Panel Extensions
- Magento 2 Size Chart Extension
- Magento 2 Security Extension
- Magento 2 Admin Action Log
- Magento 2 Order Editor
- Magento 2 Better Order Grid
- Magento 2 Extended Product Grid
- Magento 2 Product Tabs
- Magento 2 Facebook Pixel
- Magento 2 Email Attachments
- Magento 2 Admin View
- Magento 2 Admin Email Notifications
- Magento 2 Login As Customer
Magento 2 Blog Extensions
Magento 2 Marketing Automation Extensions
- Magento 2 Cookie Consent
- Magento 2 Product Labels
- Magento 2 Base Price
- Magento 2 Dynamic Categories
- Magento 2 Dynamic Blocks and Pages Extension
- Magento 2 Automatic Related Products
- Magento 2 Price History
- Magento 2 Mautic Integration
- Magento 2 YouTube Video
Magento 2 Cart Extensions
Magento 2 Multi-Language Extensions
- Magento 2 Hreflang Tags
- Magento 2 Auto Currency Switcher
- Magento 2 Auto Language Switcher
- Magento 2 GeoIP Store Switcher
- Magento 2 Translation
Developers Tools
- Magento 2 Zero Downtime Deployment
- Magento 2 Cron Schedule
- Magento 2 CLI Extension
- Magento 2 Conflict Detector
Shopify Apps by Magefan
No changelog yet
The vendor hasn't published a changelog. Tagged releases appear in the Versions tab.
| Version | Stability | QA Status | Compatibility | Released |
|---|---|---|---|---|
| 2.3.5 | stable | Fail | Magento 2.4.7-2.4.9 Details | 2025-09-29 10:18:26 |
| 2.3.4 | stable | Not tested | Not yet tested Details | 2025-09-22 11:08:56 |
| 2.3.3 | stable | Not tested | Not yet tested Details | 2025-09-08 08:34:02 |
| 2.3.2 | stable | Not tested | Not yet tested Details | 2025-05-08 12:29:25 |
| 2.3.1 | stable | Not tested | Not yet tested Details | 2024-05-24 11:08:06 |
| 2.3.0 | stable | Not tested | Not yet tested Details | 2024-05-03 08:31:33 |
| 2.2.3 | stable | Not tested | Not yet tested Details | 2023-09-06 09:21:48 |
| 2.2.2 | stable | Not tested | Not yet tested Details | 2023-03-13 08:24:00 |
| 2.2.1 | stable | Not tested | Not yet tested Details | 2023-02-17 07:08:09 |
| 2.2.0 | stable | Not tested | Not yet tested Details | 2022-09-05 08:51:05 |
| 2.1.8 | stable | Not tested | Not yet tested Details | 2022-09-01 11:54:32 |
| 2.1.7 | stable | Not tested | Not yet tested Details | 2020-07-11 10:09:13 |
| 2.1.6 | stable | Not tested | Not yet tested Details | 2020-07-11 09:50:45 |
| 2.1.5 | stable | Not tested | Not yet tested Details | 2020-06-01 10:24:15 |
| 2.1.4 | stable | Not tested | Not yet tested Details | 2020-03-17 07:20:09 |
| 2.1.3 | stable | Not tested | Not yet tested Details | 2020-01-31 08:17:44 |
| 2.1.2 | stable | Not tested | Not yet tested Details | 2019-09-09 17:08:31 |
| 2.1.1 | stable | Not tested | Not yet tested Details | 2019-07-02 18:32:50 |
| 2.1.0 | stable | Not tested | Not yet tested Details | 2019-05-24 14:51:02 |
| 2.0.6 | stable | Not tested | Not yet tested Details | 2019-01-07 11:23:28 |
| 2.0.5 | stable | Not tested | Not yet tested Details | 2018-05-16 12:00:28 |
| 2.0.4 | stable | Not tested | Not yet tested Details | 2018-05-11 07:58:43 |
| 2.0.3 | stable | Not tested | Not yet tested Details | 2018-04-13 07:32:19 |
| 2.0.2 | stable | Not tested | Not yet tested Details | 2018-02-20 19:31:09 |
| 2.0.1 | stable | Not tested | Not yet tested Details | 2018-01-29 09:20:42 |
| 2.0.0 | stable | Not tested | Not yet tested Details | 2018-01-24 19:44:56 |
Requires 2
| Package | Constraint |
|---|---|
| magefan/module-community | >=2.2.17 |
| geoip2/geoip2 | ^2.9.0 |
Suggests 2
| Package | Reason |
|---|---|
| magefan/module-auto-currency-switcher | Install GeoIP Auto Currency Switcher Extension for Magento 2 (https://magefan.com/magento-2-currency-switcher-auto-currency-by-country). Use coupon code COMPOSER-FAN to get a 10% discount on magefan.com. |
| magefan/module-auto-language-switcher | Install GeoIP Auto Language/Store Switcher Extension for Magento 2 (https://magefan.com/magento-2-auto-language-switcher). Use coupon code COMPOSER-FAN to get a 10% discount on magefan.com. |
Compatibility
Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.
Code Quality
Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.
Static analysis
Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.
| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 81 | 1 error, 80 warnings (ruleset: Magento2) — 31 auto-fixable with phpcbf |
| PHPMD | Warning | 18 | 18 rule violations (MissingImport:9, UnusedFormalParameter:4, EmptyCatchBlock:3, CyclomaticComplexity:1, NPathComplexity:1) |
| Cpd | Pass | 0 | |
| Composer validate | Info | 3 | valid; 3 advisory notes (composer validate --strict) |
PHPStan
Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.
Tests
Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.
Unit tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Integration tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Security
Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.
No license declared
This package's composer.json doesn't declare a license, homepage, or authors. Check the source repository for terms of use.
More from magefan
View vendorImplements Blog functionality on Magento 2 store
Magefan_PluginSortOrderExample
Turn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.