{"id":26728331,"url":"https://github.com/ipinfo/php","last_synced_at":"2025-05-14T14:09:01.780Z","repository":{"id":40679486,"uuid":"147048614","full_name":"ipinfo/php","owner":"ipinfo","description":"Official PHP library for IPinfo (IP geolocation and other types of IP data)","archived":false,"fork":false,"pushed_at":"2025-05-08T17:43:41.000Z","size":267,"stargazers_count":261,"open_issues_count":17,"forks_count":84,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-05-12T07:42:12.577Z","etag":null,"topics":["geoip","ip-data","ip-geolocation","ipaddress","ipinfo","php"],"latest_commit_sha":null,"homepage":"https://ipinfo.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipinfo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-09-02T02:39:43.000Z","updated_at":"2025-05-12T01:47:47.000Z","dependencies_parsed_at":"2025-02-15T04:21:40.244Z","dependency_job_id":"3ac6f222-45a6-4ead-8969-f262040cd194","html_url":"https://github.com/ipinfo/php","commit_stats":{"total_commits":233,"total_committers":64,"mean_commits":3.640625,"dds":0.8669527896995708,"last_synced_commit":"831dc1c0833b0694269dc758f84b51d926167dda"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fphp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fphp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fphp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fphp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipinfo","download_url":"https://codeload.github.com/ipinfo/php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253919707,"owners_count":21984264,"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":["geoip","ip-data","ip-geolocation","ipaddress","ipinfo","php"],"created_at":"2025-03-27T22:23:08.823Z","updated_at":"2025-05-14T14:08:56.769Z","avatar_url":"https://github.com/ipinfo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [\u003cimg src=\"https://ipinfo.io/static/ipinfo-small.svg\" alt=\"IPinfo\" width=\"24\"/\u003e](https://ipinfo.io/) IPinfo PHP Client Library\n\nThis is the official PHP client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to look up your own IP address, or get any of the following details for an IP:\n - [IP to Geolocation data](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude, and longitude)\n - [ASN information](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting, or company)\n - [Company details](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)\n - [Carrier information](https://ipinfo.io/ip-carrier-api) (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)\n\nCheck all the data we have for your IP address [here](https://ipinfo.io/what-is-my-ip).\n\n### Getting Started\n\nYou'll need an IPinfo API access token, which you can get by signing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup?ref=lib-PHP).\n\nThe free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see [https://ipinfo.io/pricing](https://ipinfo.io/pricing?ref=lib-PHP).\n\n#### Installation\n\nThe package works with PHP 8 and is available using [Composer](https://getcomposer.org).\n\n```shell\ncomposer require ipinfo/ipinfo\n``` \n\n#### Quick Start\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse ipinfo\\ipinfo\\IPinfo;\n\n$access_token = '123456789abc';\n$client = new IPinfo($access_token);\n$ip_address = '216.239.36.21';\n$details = $client-\u003egetDetails($ip_address);\n\necho $details-\u003ecity; // Mountain View\necho $details-\u003eloc; // 37.4056,-122.0775\n```\n\n### Usage\n\nThe `IPinfo-\u003egetDetails()` method accepts an IP address as an optional, positional argument. If no IP address is specified, the API will return data for the IP address from which it receives the request.\n\n```php\n$client = new IPinfo();\n$ip_address = '216.239.36.21';\n$details = $client-\u003egetDetails($ip_address);\necho $details-\u003ecity; // Mountain View\necho $details-\u003eloc; // 37.4056,-122.0775\n```\n\n### Authentication\n\nThe IPinfo library can be authenticated with your IPinfo API token, which is passed in as a positional argument. It also works without an authentication token, but in a more limited capacity.\n\n```php\n$access_token = '123456789abc';\n$client = new IPinfo($access_token);\n```\n\n### Details Data\n\n`IPinfo-\u003egetDetails()` will return a `Details` object that contains all fields listed [IPinfo developer docs](https://ipinfo.io/developers/responses#full-response) with a few minor additions. Properties can be accessed directly.\n\n```php\n$details-\u003ehostname; // cpe-104-175-221-247.socal.res.rr.com\n```\n\n#### Country Name\n\n`Details-\u003ecountry_name` will return the country name, as supplied by the `countries` object. See below for instructions on changing that object for use with non-English languages. `Details-\u003ecountry` will still return the country code.\n\n```php\n$details-\u003ecountry; // US\n$details-\u003ecountry_name; // United States\n```\n\n#### EU Country\n\n`Details-\u003eis_eu` will return true if the country is a member of the EU, as supplied by the `eu` object.\n\n```php\n$details-\u003eis_eu; // False\n```\n\n#### Country Flag\n\n`Details-\u003ecountry_flag` will return the emoji and Unicode representations of\nthe country's flag, as supplied by the `flags` object.\n\n```php\n$details-\u003ecountry_flag['emoji']; // 🇺🇸\n$details-\u003ecountry_flag['unicode']; // U+1F1FA U+1F1F8\n```\n\n#### Country Flag URL\n\n`Details-\u003ecountry_flag_url` will return a public link to the country's flag image as an SVG which can be used anywhere.\n\n```php\n$details-\u003ecountry_flag_url; // https://cdn.ipinfo.io/static/images/countries-flags/US.svg\n```\n\n#### Country Currency\n\n`Details-\u003ecountry_currency` will return the code and symbol of the \ncountry's currency, as supplied by the `currency` object.\n\n```php\n$details-\u003ecountry_currency['code']; // USD\n$details-\u003ecountry_currency['symbol']; // $\n```\n\n#### Continent\n\n`Details-\u003econtinent` will return the code and name of the \ncontinent, as supplied by the `continents` object.\n\n```php\n$details-\u003econtinent['code']; // NA\n$details-\u003econtinent['name']; // North America\n```\n\n#### Longitude and Latitude\n\n`Details-\u003elatitude` and `Details-\u003elongitude` will return latitude and longitude, respectively, as strings. `Details-\u003eloc` will still return a composite string of both values.\n\n```php\n$details-\u003eloc; // 37.4056,-122.0775\n$details-\u003elatitude; // 37.4056\n$details-\u003elongitude; // -122.0775\n```\n\n#### Accessing all properties\n\n`Details-\u003eall` will return all details data as a dictionary.\n\n```php\n$details-\u003eall;\n/*\n(\n    [ip] =\u003e 216.239.36.21\n    [hostname] =\u003e any-in-2415.1e100.net\n    [anycast] =\u003e 1\n    [city] =\u003e Mountain View\n    [region] =\u003e California\n    [country] =\u003e US\n    [loc] =\u003e 37.4056,-122.0775\n    [org] =\u003e AS15169 Google LLC\n    [postal] =\u003e 94043\n    [timezone] =\u003e America/Los_Angeles\n    [asn] =\u003e Array\n        (\n            [asn] =\u003e AS15169\n            [name] =\u003e Google LLC\n            [domain] =\u003e google.com\n            [route] =\u003e 216.239.36.0/24\n            [type] =\u003e hosting\n        )\n\n    [company] =\u003e Array\n        (\n            [name] =\u003e Google LLC\n            [domain] =\u003e google.com\n            [type] =\u003e hosting\n        )\n\n    [privacy] =\u003e Array\n        (\n            [vpn] =\u003e \n            [proxy] =\u003e \n            [tor] =\u003e \n            [relay] =\u003e \n            [hosting] =\u003e 1\n            [service] =\u003e \n        )\n\n    [abuse] =\u003e Array\n        (\n            [address] =\u003e US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043\n            [country] =\u003e US\n            [email] =\u003e network-abuse@google.com\n            [name] =\u003e Abuse\n            [network] =\u003e 216.239.32.0/19\n            [phone] =\u003e +1-650-253-0000\n        )\n\n    [domains] =\u003e Array\n        (\n            [ip] =\u003e 216.239.36.21\n            [total] =\u003e 2535948\n            [domains] =\u003e Array\n                (\n                    [0] =\u003e pub.dev\n                    [1] =\u003e virustotal.com\n                    [2] =\u003e blooket.com\n                    [3] =\u003e go.dev\n                    [4] =\u003e rytr.me\n                )\n\n        )\n\n    [country_name] =\u003e United States\n    [is_eu] =\u003e \n    [country_flag] =\u003e Array\n        (\n            [emoji] =\u003e 🇺🇸\n            [unicode] =\u003e U+1F1FA U+1F1F8\n        )\n\n    [country_flag_url] =\u003e https://cdn.ipinfo.io/static/images/countries-flags/US.svg\n    [country_currency] =\u003e Array\n        (\n            [code] =\u003e USD\n            [symbol] =\u003e $\n        )\n\n    [continent] =\u003e Array\n        (\n            [code] =\u003e NA\n            [name] =\u003e North America\n        )\n\n    [latitude] =\u003e 37.4056\n    [longitude] =\u003e -122.0775\n)\n\n*/\n```\n\n### Caching\n\nIn-memory caching of `Details` data is provided by default via the [symfony/cache](https://github.com/symfony/cache/) library. LRU (least recently used) cache-invalidation functionality has been added to the default TTL (time to live). This means that values will be cached for the specified duration; if the cache's max size is reached, cache values will be invalidated as necessary, starting with the oldest cached value.\n\n#### Modifying cache options\n\nDefault cache TTL and maximum size can be changed by setting values in the `$settings` argument array.\n\n* Default maximum cache size: 4096 (multiples of 2 are recommended to increase efficiency)\n* Default TTL: 24 hours (in seconds)\n\n```php\n$access_token = '123456789abc';\n$settings = ['cache_maxsize' =\u003e 30, 'cache_ttl' =\u003e 128];\n$client = new IPinfo($access_token, $settings);\n```\n\n#### Using a different cache\n\nIt's possible to use a custom cache by creating a child class of the [CacheInterface](https://github.com/ipinfo/php/blob/master/src/cache/Interface.php) class and passing this into the handler object with the `cache` keyword argument. FYI this is known as [the Strategy Pattern](https://sourcemaking.com/design_patterns/strategy).\n\n```php\n$access_token = '123456789abc';\n$settings = ['cache' =\u003e $my_fancy_custom_cache];\n$client = new IPinfo($access_token, $settings);\n```\n\n#### Disabling the cache\n\nYou may disable the cache by passing in a `cache_disabled` key in the settings:\n\n```php\n$access_token = '123456789abc';\n$settings = ['cache_disabled' =\u003e true];\n$client = new IPinfo($access_token, $settings);\n```\n\n### Overriding HTTP Client options\n\nThe IPinfo client constructor accepts a `timeout` key which is the request\ntimeout in seconds.\n\nFor full flexibility, a `guzzle_opts` key is accepted which accepts an\nassociative array which is described in [Guzzle Request Options](https://docs.guzzlephp.org/en/stable/request-options.html).\nOptions set here will override any custom settings set by the IPinfo client\ninternally in case of conflict, including headers.\n\n### Batch Operations\n\nLooking up a single IP at a time can be slow. It could be done concurrently from the client side, but IPinfo supports a batch endpoint to allow you to group together IPs and let us handle retrieving details for them in bulk for you.\n\n```php\n$access_token = '123456789abc';\n$client = new IPinfo($access_token);\n$ips = ['1.1.1.1', '8.8.8.8', '1.2.3.4/country'];\n$results = $client-\u003egetBatchDetails($ips);\necho $results['1.2.3.4/country']; // AU\nvar_dump($results['1.1.1.1']);\nvar_dump($results['8.8.8.8']);\n```\n\nThe input size is not limited, as the interface will chunk operations for you behind the scenes.\n\nPlease see [the official documentation](https://ipinfo.io/developers/batch) for more information and limitations.\n\n### Internationalization\n\nWhen looking up an IP address, the response object includes a `Details-\u003ecountry_name` attribute which includes the country name based on American English. It is possible to return the country name in other languages by setting the `countries` object inside the `IPinfo` object, when creating the `IPinfo` object.\n\nThe `php` object must be with the following structure:\n\n```php\ncountries = [\n    \"BD\" =\u003e \"Bangladesh\",\n    \"BE\" =\u003e \"Belgium\",\n    \"BF\" =\u003e \"Burkina Faso\",\n    \"BG\" =\u003e \"Bulgaria\"\n    ...\n]\n```\n```php\ncontinents = [\n        \"BD\" =\u003e [\"code\" =\u003e \"AS\", \"name\" =\u003e \"Asia\"],\n        \"BE\" =\u003e [\"code\" =\u003e \"EU\", \"name\" =\u003e \"Europe\"],\n        \"BF\" =\u003e [\"code\" =\u003e \"AF\", \"name\" =\u003e \"Africa\"],\n        \"BG\" =\u003e [\"code\" =\u003e \"EU\", \"name\" =\u003e \"Europe\"],\n        \"BA\" =\u003e [\"code\" =\u003e \"EU\", \"name\" =\u003e \"Europe\"],\n        \"BB\" =\u003e [\"code\" =\u003e \"NA\", \"name\" =\u003e \"North America\"]\n        ...\n]\n```\n\n### Other Libraries\n\nThere are official IPinfo client libraries available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails, and Laravel. There are also many third-party libraries and integrations available for our API.\n\n### About IPinfo\n\nFounded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, privacy, hosted domains and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.\n\n[![image](https://avatars3.githubusercontent.com/u/15721521?s=128\u0026u=7bb7dde5c4991335fb234e68a30971944abc6bf3\u0026v=4)](https://ipinfo.io/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipinfo%2Fphp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipinfo%2Fphp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipinfo%2Fphp/lists"}