{"id":15025280,"url":"https://github.com/nathan-fiscaletti/ipstackgeo-php","last_synced_at":"2025-04-09T20:03:51.623Z","repository":{"id":45228067,"uuid":"115560334","full_name":"nathan-fiscaletti/ipstackgeo-php","owner":"nathan-fiscaletti","description":"📍 A PHP library for interfacing with IPStack Geo API","archived":false,"fork":false,"pushed_at":"2022-02-04T10:17:12.000Z","size":89,"stargazers_count":10,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T20:03:45.051Z","etag":null,"topics":["composer","freegeoip","freegeoip-apis","ipstack","ipstack-api","php","php-7"],"latest_commit_sha":null,"homepage":"https://ipstack.net","language":"PHP","has_issues":true,"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/nathan-fiscaletti.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-12-27T21:51:44.000Z","updated_at":"2021-12-30T21:10:07.000Z","dependencies_parsed_at":"2022-07-19T00:47:09.508Z","dependency_job_id":null,"html_url":"https://github.com/nathan-fiscaletti/ipstackgeo-php","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathan-fiscaletti%2Fipstackgeo-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathan-fiscaletti%2Fipstackgeo-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathan-fiscaletti%2Fipstackgeo-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathan-fiscaletti%2Fipstackgeo-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathan-fiscaletti","download_url":"https://codeload.github.com/nathan-fiscaletti/ipstackgeo-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103864,"owners_count":21048245,"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":["composer","freegeoip","freegeoip-apis","ipstack","ipstack-api","php","php-7"],"created_at":"2024-09-24T20:01:57.958Z","updated_at":"2025-04-09T20:03:51.601Z","avatar_url":"https://github.com/nathan-fiscaletti.png","language":"PHP","funding_links":["https://github.com/sponsors/nathan-fiscaletti"],"categories":[],"sub_categories":[],"readme":"# IPStack for PHP (Geo Location Library)\n\u003e **IPStack for PHP** is a simple library used to interface with an IPStack Geo API.\n\n```\n$ composer require nafisc/ipstackgeo-php\n```\n\n[![Sponsor Me!](https://img.shields.io/badge/%F0%9F%92%B8-Sponsor%20Me!-blue)](https://github.com/sponsors/nathan-fiscaletti)\n[![Maintainability](https://api.codeclimate.com/v1/badges/2cbb563c1ef04059df2d/maintainability)](https://codeclimate.com/github/nathan-fiscaletti/ipstackgeo-php/maintainability)\n[![StyleCI](https://styleci.io/repos/115560334/shield?style=flat)](https://styleci.io/repos/115560334)\n[![CircleCI](https://circleci.com/gh/nathan-fiscaletti/ipstackgeo-php.svg?style=svg)](https://circleci.com/gh/nathan-fiscaletti/ipstackgeo-php)\n[![Coverage Status](https://coveralls.io/repos/github/nathan-fiscaletti/ipstackgeo-php/badge.svg)](https://coveralls.io/github/nathan-fiscaletti/ipstackgeo-php)\n[![Latest Stable Version](https://poser.pugx.org/nafisc/ipstackgeo-php/v/stable?format=flat)](https://packagist.org/packages/nafisc/ipstackgeo-php)\n[![License](https://poser.pugx.org/nafisc/ipstackgeo-php/license?format=flat)](https://packagist.org/packages/nafisc/ipstackgeo-php)\n\nLearn more about IPStack here: [ipstack.net](https://ipstack.com/product)\n\n[Looking for the Python version?](https://github.com/nathan-fiscaletti/ipstackgeo-py)\n\n[Looking for the Node.JS version?](https://github.com/nathan-fiscaletti/ipstackgeo-js)\n\n### Features\n* Retrieve the Geo Location data for any IP address.\n* Retrieve the Geo Location data for the system executing this code.\n* Retrieve the Geo Location data for a client.\n* Retrieve the Geo Location data for a batch of IP addresses.\n* Assess the security of an IP address.\n\n### Legacy Features\n* Link to a custom FreeGeoIP server\n\n---\n\n### Basic Usage\n\n```php\n$geo = new GeoLookup('.....');\n$location = $geo-\u003egetLocation('github.com');\nprint_r($location);\n```\n\n### Example Usage\n\n\u003e Note: See [IPStack: Response Objects](https://ipstack.com/documentation#objects) for a list of available properties in a response object.\n\n#### Create the GeoLookup object\n\n```php\nuse IPStack\\PHP\\GeoLookup;\n\n// Create the GeoLookup object using your API key.\n$geoLookup = new GeoLookup('acecac3893c90871c3');\n```\n\n#### Lookup a location for an IP Address\n\n```php\n// Lookup a location for an IP Address\n// and catch any exceptions that might\n// be thrown by Guzzle or IPStack.\ntry {\n    // Retrieve the location information for \n    // github.com by using it's hostname.\n    // \n    // This function will work with hostnames\n    // or IP addresses.\n    $location = $geoLookup-\u003egetLocation('github.com');\n\n    // If we are unable to retrieve the location information\n    // for an IP address, null will be returned.\n    if (\\is_null($location)) {\n        echo 'Failed to find location.'.PHP_EOL;\n    } else {\n        // Print the Location Object.\n        print_r($location);\n    }\n} catch (\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n```\n\n#### Look up a Clients location\n\n```php\n$location = $geoLookup-\u003egetClientLocation();\nprint_r($location);\n```\n\n#### Look up own location\n```php\n$location = $geoLookup-\u003egetOwnLocation();\nprint_r($location);\n```\n\n#### Other Features\n\nThere are also a few other useful features built into this library and the IPStack API.\n\n1. Bulk Location Lookup\n\n   The ipstack API also offers the ability to request data for multiple IPv4 or IPv6 addresses at the same time. This requires the PROFESSIONAL teir API key or higher and is limitted to 50 IPs at a time.\n   \u003e See: [https://ipstack.com/documentation#bulk](https://ipstack.com/documentation#bulk)\n\n   ```php\n   $lookup = ['google.com', 'github.com', '1.1.1.1'];\n   $locations = $geoLookup-\u003egetLocations(...$lookup);\n   print_r($locations);\n   ```\n\n2. Requesting the hostname for an IP address.\n\n   By default, the ipstack API does not return information about the hostname the given IP address resolves to. In order to include the hostname use the following.\n   \u003e See: [https://ipstack.com/documentation#hostname](https://ipstack.com/documentation#hostname)\n\n   ```php\n   $location = $geoLookup-\u003esetFindHostname(true)-\u003egetLocation('1.1.1.1');\n   echo $location['hostname'];\n   ```\n\n   ```\n   one.one.one.one\n   ```\n\n3. Assessing Security\n\n   Customers subscribed to the Professional Plus Plan may access the ipstack API's Security Module, which can be used to assess risks and threats originating from certain IP addresses before any harm can be done to a website or web application.\n   \u003e See: [https://ipstack.com/documentation#security](https://ipstack.com/documentation#security)\n\n   ```php\n   $location = $geoLookup-\u003eassessSecurity(true)-\u003egetLocation('github.com');\n   ```\n\n4. Set the language for a response\n\n   The ipstack API is capable of delivering its result set in different languages. To request data in a language other than English (default) use following with one of the supported language codes.\n   \u003e See: [https://ipstack.com/documentation#language](https://ipstack.com/documentation#language)\n\n   [Supported Langauges](https://ipstack.com/documentation#language)\n\n   ```php\n   $location = $geoLookup-\u003esetLanguage('en')-\u003egetLocation('github.com');\n   ```\n\n5. Configuring your request\n\n   ```php\n   /// Use HTTPS\n   /// This requires IPStack Basic plan or higher.\n   $location = $geoLookup-\u003euseHttps(true)-\u003egetLocation('github.com');\n\n   /// Configure the timeout for requests\n   $location = $geoLookup-\u003esetTimeout(15)-\u003egetLocation('github.com');\n   ```\n\n\n#### Using the the Legacy [FreeGeoIP Binary](https://github.com/fiorix/freegeoip/releases/)\n\nYou can still use the legacy FreeGeoIP Binary hosted on a server\n\u003e Note: [FreeGeoIP has been deprecated](https://github.com/apilayer/freegeoip/#freegeoip---important-announcement).\n\n```php\nuse IPStack\\PHP\\Legacy\\FreeGeoIp as GeoLookup;\n\n// Address, Port, Protocol, Timeout\n$geoLookup = new GeoLookup(\n    'localhost', // Address hosting the legacy FreeGeoIP Binary\n    8080,        // Port that the binary is running on (defaults to 8080)\n    'http',      // Protocol to use (defaults to http)\n    10           // Timeout (defaults to 10 seconds)\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathan-fiscaletti%2Fipstackgeo-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathan-fiscaletti%2Fipstackgeo-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathan-fiscaletti%2Fipstackgeo-php/lists"}