{"id":16695175,"url":"https://github.com/davidepastore/ipinfo","last_synced_at":"2025-05-07T17:49:25.502Z","repository":{"id":21664691,"uuid":"24985619","full_name":"DavidePastore/ipinfo","owner":"DavidePastore","description":"A wrapper around the ipinfo.io services","archived":false,"fork":false,"pushed_at":"2022-12-20T19:22:04.000Z","size":213,"stargazers_count":52,"open_issues_count":0,"forks_count":18,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-16T20:57:25.082Z","etag":null,"topics":["geolocation","ip","ipinfo","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DavidePastore.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":"2014-10-09T11:10:15.000Z","updated_at":"2024-08-25T14:36:41.000Z","dependencies_parsed_at":"2023-01-13T21:37:11.618Z","dependency_job_id":null,"html_url":"https://github.com/DavidePastore/ipinfo","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidePastore%2Fipinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidePastore%2Fipinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidePastore%2Fipinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidePastore%2Fipinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DavidePastore","download_url":"https://codeload.github.com/DavidePastore/ipinfo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252931355,"owners_count":21827102,"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":["geolocation","ip","ipinfo","php"],"created_at":"2024-10-12T17:05:45.429Z","updated_at":"2025-05-07T17:49:25.484Z","avatar_url":"https://github.com/DavidePastore.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"ipinfo\n======\n\n[![Latest version][ico-version]][link-packagist]\n[![Build Status][ico-github-actions]][link-github-actions]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![PSR2 Conformance][ico-styleci]][link-styleci]\n\n\nA wrapper around the [ipinfo.io](http://ipinfo.io/) services.\n\n\nInstall\n-------\n\nYou can install the library using [composer](https://getcomposer.org/):\n\n```sh\n$ composer require davidepastore/ipinfo\n```\n\nHow to use\n----------\n\n### Settings\n\n#### Token\n\nYou can set your token when you instantiate the object but it's not mandatory.\n\n```php\n$ipInfo = new DavidePastore\\Ipinfo\\Ipinfo(array(\n\t\"token\" =\u003e \"your_api_key\"\n));\n```\n\n#### cURL options\n\nThe cURL options to use while trying to connect when you instantiate the object:\n\n```php\n$ipInfo = new DavidePastore\\Ipinfo\\Ipinfo(array(\n\t\"curlOptions\" =\u003e array(\n            CURLOPT_CONNECTTIMEOUT =\u003e 1,\n            CURLOPT_TIMEOUT =\u003e 2,\n            CURLOPT_CAINFO =\u003e __DIR__ . \"/cacert.pem\"\n    )\n));\n```\n\n### Read details about the given ip\n\nYou can read all the properties from the given ip.\n\n```php\n//Get all the properties\n$host = $ipInfo-\u003egetFullIpDetails(\"8.8.8.8\");\n\n//Get only a single property (this could save bandwidth)\n$city = $ipInfo-\u003egetSpecificField(\"8.8.8.8\", DavidePastore\\Ipinfo\\Ipinfo::CITY);\n```\n\n### Read details about your ip\n\nYou can read all the properties from your ip.\n\n```php\n//Get all the properties\n$host = $ipInfo-\u003egetYourOwnIpDetails();\n\n//Get only a single property (this could save bandwidth)\n$city = $ipInfo-\u003egetYourOwnIpSpecificField(DavidePastore\\Ipinfo\\Ipinfo::CITY);\n```\n\n### Get info from the host\n\nAfter obtaining the `Host` instance you can read all the properties or each of them individually.\n\n```php\n//Read all the properties\n$city = $host-\u003egetCity();\n$country = $host-\u003egetCountry();\n$hostname = $host-\u003egetHostname();\n$ip = $host-\u003egetIp();\n$loc = $host-\u003egetLoc();\n$org = $host-\u003egetOrg();\n$phone = $host-\u003egetPhone();\n$postal = $host-\u003egetPostal();\n$region = $host-\u003egetRegion();\n\n//Get the associative array with all the properties\n$properties = $host-\u003egetProperties();\n```\n\n### Read only a field\n\nThere are different constants that you could use to read specific field value from an `Ipinfo` instance using the `getSpecificField()` and `getYourOwnIpSpecificField()` methods:\n\n```php\nIpInfo::IP; //For the ip address\nIpInfo::HOSTNAME; //For the hostname\nIpInfo::LOC; //For the loc\nIpInfo::ORG; //For the org\nIpInfo::CITY; //For the city\nIpInfo::REGION; //For the region\nIpInfo::COUNTRY; //For the country\nIpInfo::PHONE; //For the phone\nIpInfo::POSTAL; //For the postal\nIpInfo::GEO; //For the geo info. See the paragraph below for more info\n```\n\n### Read only the Geo data (which is faster)\n\nBy using the `getIpGeoDetails()` method you will get less fields. This call tends to be faster than `getFullIpDetails()` so use this call in case you only need the following fields:\n\n```php\nIpInfo::IP; //For the ip address\nIpInfo::CITY; //For the city\nIpInfo::REGION; //For the region\nIpInfo::COUNTRY; //For the country\nIpInfo::PHONE; //For the phone\nIpInfo::POSTAL; //For the postal\n```\n\nThese fields will be empty:\n```php\nIpInfo::HOSTNAME; //For the hostname\nIpInfo::LOC; //For the loc\nIpInfo::ORG; //For the org\n```\n\n### Error Handling\n\nYou can handle all the types of IpInfo exceptions by catching the `IpInfoExceptionException`:\n\n```php\nuse DavidePastore\\Ipinfo\\Exception\\IpInfoExceptionException;\n\ntry {\n    $host = $ipInfo-\u003egetFullIpDetails(\"8.8.8.8\");\n} catch (IpInfoExceptionException $e) {\n    echo 'Caught exception: ',  $e-\u003egetMessage(), \"\\n\";\n}\n```\n\n#### Invalid Token Exception\n\nIt could happen that the token you are using to make the API call is not valid. You can handle it by catching the `InvalidTokenException`:\n\n```php\nuse DavidePastore\\Ipinfo\\Exception\\InvalidTokenException;\n\ntry {\n    $host = $ipInfo-\u003egetFullIpDetails(\"8.8.8.8\");\n} catch (InvalidTokenException $e) {\n    echo 'Caught exception: ',  $e-\u003egetMessage(), \"\\n\";\n}\n```\n\n#### Rate Limit Exceed Exception\n\nIt could happen that your API call exceeds the rate limit. You can handle it by catching the `RateLimitExceedException`:\n\n```php\nuse DavidePastore\\Ipinfo\\Exception\\RateLimitExceedException;\n\ntry {\n    $host = $ipInfo-\u003egetFullIpDetails(\"8.8.8.8\");\n} catch (RateLimitExceedException $e) {\n    echo 'Caught exception: ',  $e-\u003egetMessage(), \"\\n\";\n}\n```\n\n#### Wrong Ip Exception\n\nIt could happen that your API call is trying to obtain info about a wrong ip. You can handle it by catching the `WrongIpException`:\n\n```php\nuse DavidePastore\\Ipinfo\\Exception\\WrongIpException;\n\ntry {\n    $host = $ipInfo-\u003egetFullIpDetails(\"qwerty\");\n} catch (WrongIpException $e) {\n    echo 'Caught exception: ',  $e-\u003egetMessage(), \"\\n\";\n}\n```\n\nIssues\n-------\n\nIf you have issues, just open one [here](https://github.com/DavidePastore/ipinfo/issues).\n\n\n[ico-version]: https://img.shields.io/packagist/v/DavidePastore/ipinfo.svg?style=flat-square\n[ico-github-actions]: https://github.com/DavidePastore/ipinfo/workflows/Continuous%20Integration/badge.svg?branch=master\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/DavidePastore/ipinfo.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/davidepastore/ipinfo.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/DavidePastore/ipinfo.svg?style=flat-square\n[ico-styleci]: https://styleci.io/repos/24985619/shield\n\n[link-packagist]: https://packagist.org/packages/DavidePastore/ipinfo\n[link-github-actions]: https://github.com/DavidePastore/ipinfo/actions?query=workflow%3A%22Continuous+Integration%22\n[link-scrutinizer]: https://scrutinizer-ci.com/g/DavidePastore/ipinfo/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/DavidePastore/ipinfo\n[link-downloads]: https://packagist.org/packages/DavidePastore/ipinfo\n[link-styleci]: https://styleci.io/repos/24985619/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidepastore%2Fipinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidepastore%2Fipinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidepastore%2Fipinfo/lists"}