{"id":15984863,"url":"https://github.com/divineomega/php-geolocation","last_synced_at":"2025-03-18T00:31:40.266Z","repository":{"id":25538883,"uuid":"104403497","full_name":"DivineOmega/php-geolocation","owner":"DivineOmega","description":"PHP library that determines the country of an IP address","archived":false,"fork":false,"pushed_at":"2022-01-12T10:45:59.000Z","size":21,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-15T02:37:15.951Z","etag":null,"topics":["country","geolocation","ip","location","php","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DivineOmega.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":"2017-09-21T22:06:27.000Z","updated_at":"2023-08-01T12:51:29.000Z","dependencies_parsed_at":"2022-07-26T07:02:15.933Z","dependency_job_id":null,"html_url":"https://github.com/DivineOmega/php-geolocation","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fphp-geolocation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fphp-geolocation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fphp-geolocation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Fphp-geolocation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DivineOmega","download_url":"https://codeload.github.com/DivineOmega/php-geolocation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221703983,"owners_count":16866656,"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","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":["country","geolocation","ip","location","php","php-library"],"created_at":"2024-10-08T02:10:51.078Z","updated_at":"2024-10-27T16:25:09.607Z","avatar_url":"https://github.com/DivineOmega.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Geolocation\n\n[![Build Status](https://travis-ci.com/DivineOmega/php-geolocation.svg?branch=master)](https://travis-ci.com/DivineOmega/php-geolocation)\n\nThis package provides a PHP library that determines the country of an IP address.\n\n## Installation\n\nYou can easily install PHP Geolocation with composer.\n\n```\ncomposer require divineomega/php-geolocation\n```\n\n## Usage\n\nThe most simple usage of PHP Geolocation is to create a new Locator object and call its `getCountryByIP` method.\n\n```php\n// Get country of the current request's IP address\n$country = (new Locator)-\u003egetCountryByIP($_SERVER['REMOTE_ADDR']);\n\n// Get country of a specific IP address\n$country = (new Locator)-\u003egetCountryByIP('93.184.216.34');\n\n// Returns a Country object\n/*\nobject(DivineOmega\\Countries\\Country)#4693 (16) {\n  [\"name\"]=\u003e\n  string(13) \"United States\"\n  [\"officialName\"]=\u003e\n  string(24) \"United States of America\"\n  // etc...\n}\n*/\n```\n\n### Caching\n\nYou can configure PHP Geolocation to use any PSR-6 compliant caching library. This is easily done using the `setCache` method.\n\nThe following example configures a file cache (provided by the `cache/filesystem-adapter` package).\n\n```php\nuse League\\Flysystem\\Adapter\\Local;\nuse League\\Flysystem\\Filesystem;\nuse Cache\\Adapter\\Filesystem\\FilesystemCachePool;\n\n$filesystemAdapter = new Local(__DIR__.'/');\n$filesystem = new Filesystem($filesystemAdapter);\n$cachePool = new FilesystemCachePool($filesystem);\n\n$locator = new Locator;\n$locator-\u003esetCache($cachePool);\n\n$country = $locator-\u003egetCountryByIP('93.184.216.34');\n```\n\n### Alternative location providers\n\nBy default, PHP Geolocation will try to use the operating system's native `whois` command to determine the IP address. If you wish you\ncan use an alternative location provider. This can be done using the `setLocationProvider` method, as follows.\n\n```php\n$locator = new Locator;\n$locator-\u003esetLocationProvider(new IpStack('my_ip_stack_api_key');\n\n$country = $locator-\u003egetCountryByIP('93.184.216.34');\n```\n\n_To get a free api key sign up at [Ip Stack's website](https://ipstack.com)._\n\nIf you wish to develop your own location provider, simply create a new class that implements the `LocationProviderInterface` provided in\nthis package. See the existing `WhoIs` and `FreeGeoIP` location provider classes if you need help creating your own location provider.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivineomega%2Fphp-geolocation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdivineomega%2Fphp-geolocation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivineomega%2Fphp-geolocation/lists"}