{"id":18750690,"url":"https://github.com/webiny/geoip","last_synced_at":"2025-08-12T12:39:36.001Z","repository":{"id":62547933,"uuid":"47077554","full_name":"webiny/GeoIp","owner":"webiny","description":"[NOT MAINTAINED] Geolocation component using MaxMind GeoLite2 or FreeGeoIp API.","archived":false,"fork":false,"pushed_at":"2017-09-08T11:12:09.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-20T11:09:21.672Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webiny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-29T19:48:06.000Z","updated_at":"2023-05-27T16:34:34.000Z","dependencies_parsed_at":"2022-11-02T22:16:21.869Z","dependency_job_id":null,"html_url":"https://github.com/webiny/GeoIp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/webiny/GeoIp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FGeoIp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FGeoIp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FGeoIp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FGeoIp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/GeoIp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FGeoIp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270063362,"owners_count":24520750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T17:12:49.616Z","updated_at":"2025-08-12T12:39:35.973Z","avatar_url":"https://github.com/webiny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"GeoIp\n=================\n\nGeoIp is a simple component providing location information for a given IPv4 or IPv6 address.\n\nExample:\n\n```php\n$geo = new \\Webiny\\GeoIp\\GeoIp(new \\Webiny\\GeoIp\\Provider\\FreeGeoIp\\FreeGeoIp());\n$location = $geo-\u003egetGeoIpLocation('8.8.8.8');\n\n// output\narray(\n   'continentCode' =\u003e NULL,\n   'continentName' =\u003e NULL,\n   'countryCode' =\u003e 'US',\n   'countryName' =\u003e 'United States',\n   'cityName' =\u003e 'Mountain View',\n   'subdivision1Code' =\u003e 'CA',\n   'subdivision1Name' =\u003e 'California',\n   'subdivision2Code' =\u003e NULL,\n   'subdivision2Name' =\u003e NULL,\n   'timeZone' =\u003e 'America/Los_Angeles',\n)\n```\n\nDepending on the provider, different information will be available.\nThe GeoIp standard library comes with 2 providers:\n- `FreeGeoIp`: uses the https://freegeoip.net/ API\n- `MaxMindGeoLite2`: uses the GeoLite2 database provided by MaxMind (requires a Mongo database)\n\nInstall GeoIp\n---------------------\nThe best way to install the component is using Composer.\n\n```bash\ncomposer require webiny/geoip\n```\nFor additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/geoip).\n\n\n## Setup\n\n### FreeGeoIp\n\nIf you plan to use the `FreeGeoIp` API, no setup is required, just create a provider instance and pass it to the `GeoIp` class, like so:\n\n```php\n$providerInstance = new \\Webiny\\GeoIp\\Provider\\FreeGeoIp\\FreeGeoIp()\n\n$geo = new \\Webiny\\GeoIp\\GeoIp($providerInstance);\n$location = $geo-\u003egetGeoIpLocation('8.8.8.8');\n```\n\n### MaxMindGeoLite2\n\nThis provider requires a Mongo database, that is configured using `Webiny\\Mongo` component. \nIn addition to the database, some other parameters are also required, so here is an example config:\n\n```yaml\nMaxMind:\n    GeoLite2Url: http://geolite.maxmind.com/download/geoip/database/GeoLite2-City-CSV.zip\n    Language:  en\nEntity:\n    Database: GeoIp\nMongo:\n    Services:\n        GeoIp:\n            Class: \\Webiny\\Component\\Mongo\\Mongo\n            Arguments:\n                Host: 127.0.0.1:27017\n                Database: YourDatabase ## CHANGE THIS\n                Username: null\n                Password: null\n                CollectionPrefix: ''\n```\n\nThe `MaxMind` section defines the download location of the GeoLite2 database and the language for the location name that will be imported from that database.\nThe `Entity` and `Mongo` section are standard configurations as described under `Webiny/Entity` and `Webiny/Mongo` components.\n\nOnce you have your configuration in place, run the following command in your terminal:\n\n``` bash\nphp /path/to/src/Webiny/GeoIp/Provider/MaxMindGeoLite2/run-installer.php abs-path-to-your-config-yaml-file\n```\n\nThis will download the GeoLite2 database and setup the Mongo collections for you. Note that the process might take up to 15-30 min, depending on your hardware.\n\nOnce the installation finishes, you can use the provider like so:\n\n```php\n$config = 'abs-path-to-your-config-yaml-file';\n$provider = new Webiny\\GeoIp\\Provider\\MaxMindGeoLite2\\MaxMindGeoLite2($config);\n\n$geo = new \\Webiny\\GeoIp\\GeoIp($provider);\n$location = $geo-\u003egetGeoIpLocation('8.8.8.8');\n```\n\n### Custom provider\n\nIf you wish to implement a custom provider, just create a class for your provider that implements `Webiny\\GeoIp\\ProviderInterface`;\n\n\n## Location class\n\nThe location class is the result of the geo ip lookup. \nDepending on the provider, the amount of information might vary.\nOverall, a typical lookup result looks like this:\n\n```php\nWebiny/GeoIp/Location::__set_state(array(\n   'continentCode' =\u003e 'NA',\n   'continentName' =\u003e 'North America',\n   'countryCode' =\u003e 'US',\n   'countryName' =\u003e 'United States',\n   'cityName' =\u003e 'Mountain View',\n   'subdivision1Code' =\u003e 'CA',\n   'subdivision1Name' =\u003e 'California',\n   'subdivision2Code' =\u003e '',\n   'subdivision2Name' =\u003e '',\n   'timeZone' =\u003e 'America/Los_Angeles',\n))\n```\n\nNote that if the location cannot be determined, `false` will be returned instead of the `Location` instance.\n\n## License and Contributions\n\nContributing \u003e Feel free to send PRs.\n\nLicense \u003e [MIT](LICENSE)\n\n## Resources\n\nTo run unit tests, you need to use the following command:\n```\n$ cd path/to/GeoIp/\n$ composer install\n$ phpunit\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fgeoip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Fgeoip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fgeoip/lists"}