{"id":13404985,"url":"https://github.com/IPGeolocation/ip-geolocation-api-php","last_synced_at":"2025-03-14T09:32:08.750Z","repository":{"id":33687772,"uuid":"143417066","full_name":"IPGeolocation/ip-geolocation-api-php","owner":"IPGeolocation","description":"IP Geolocation API PHP SDK","archived":false,"fork":false,"pushed_at":"2022-03-31T12:40:01.000Z","size":24,"stargazers_count":32,"open_issues_count":2,"forks_count":20,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-07-31T19:44:52.524Z","etag":null,"topics":["ip-geolocation-api","ip-location","php","timezone-api"],"latest_commit_sha":null,"homepage":"https://ipgeolocation.io/documentation/ip-geolocation-api-php-sdk-201809051255","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/IPGeolocation.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":"2018-08-03T11:06:14.000Z","updated_at":"2024-06-13T15:15:28.000Z","dependencies_parsed_at":"2022-08-07T23:00:21.848Z","dependency_job_id":null,"html_url":"https://github.com/IPGeolocation/ip-geolocation-api-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IPGeolocation%2Fip-geolocation-api-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IPGeolocation%2Fip-geolocation-api-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IPGeolocation%2Fip-geolocation-api-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IPGeolocation%2Fip-geolocation-api-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IPGeolocation","download_url":"https://codeload.github.com/IPGeolocation/ip-geolocation-api-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221454063,"owners_count":16824596,"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":["ip-geolocation-api","ip-location","php","timezone-api"],"created_at":"2024-07-30T19:01:54.161Z","updated_at":"2024-10-25T19:31:26.052Z","avatar_url":"https://github.com/IPGeolocation.png","language":"PHP","readme":"# IP Geolocation API PHP SDK\n\n## Introduction\n\n[IPGeolocation API](https://ipgeolocation.io) is the solution to identify country code (ISO2 and ISO3 standard), country name, continent code, continent name, country capital, state/province, district, city, zip code, latitude and longitude of city, is country belongs to Europian Union, calling code, top level domain (TLD), languages, country flag, internet service provider (ISP), connection type, organization, geoname ID, currency code, currency name, time zone ID, time zone offset, current time in the time zone, is time zone in daylight saving time, and total daylight savings. This document provides important information to help you get up to speed with IPGeolocation API using IP Geolocation API PHP SDK.\n\nDevelopers can use this PHP SDK for software and web projects related to, but not limited to:\n\n1. Display native language and currency\n2. Redirect based on the country\n3. Digital rights management\n4. Web log stats and analysis\n5. Auto-selection of country, state/province and city on forms\n6. Filter access from countries you do not do business with\n7. Geo-targeting for increased sales and click-through\n\n## Quick Start Guide\n\nYou need a valid 'IPGeolocation API key' to use this SDK. [Sign up](https://ipgeolocation.io/signup) here and get your free API key if you don't have one.\n\n**Note:** Complete documentation to use this SDK is also available at [IP Geolocation API PHP SDK Documentation](https://ipgeolocation.io/documentation/ip-geolocation-api-php-sdk-201809051255).\n\n## System Requirements  \n\nInternet connection is required to run this component.\n\n## Documentation\nUse the following URL to visit documentation\n[https://ipgeolocation.io/documentation.html](https://ipgeolocation.io/documentation.html)\n\n\n## Basic Usage\n\nCall method **get_geolocation($apiKey, $ip, $lang, $fields, $excludes)** passing _API key_ and _IP address_ as parameters (rest of the parameters are optional) and it will return the Geolocation for the passed IP address.\nTo customize the geolocation response, you can pass the other parameters to **get_geolocation** method as described below:\n\n* $lang  \nPass the _language_ parameter to get the geolocation information in a language other than English. By default, it is set to English language.  \nIPGeolocation provides response in the following languages:\n  * English (en)\n  * German (de)\n  * Russian (ru)\n  * Japanese (ja)\n  * French (fr)\n  * Chinese Simplified (cn)\n  * Spanish (es)\n  * Czech (cs)\n  * Italian (it)  \n  Only the paid plan subscriptions can get the response in languages other than English. All the other users will only get the response in English.\n\n* $fields  \nPass the _fields_ parameter to get the specified fields only. By default, it is set to get all the fields in the response.\n\n* $excludes\nPass the _exlcludes_ parameter to get remove the unnecessary fields from the response. By default, it set to not to exclude any fields.\n\n```php\n\u003c?php\n    $apiKey = \"PUT_YOUR_API_KEY_HERE\";\n    $ip = \"CLIENT_IP_ADDRESS\";\n    $location = get_geolocation($apiKey, $ip);\n    $decodedLocation = json_decode($location, true);\n    \n    echo \"\u003cpre\u003e\";\n    print_r($decodedLocation);\n    echo \"\u003c/pre\u003e\";\n\n    function get_geolocation($apiKey, $ip, $lang = \"en\", $fields = \"*\", $excludes = \"\") {\n        $url = \"https://api.ipgeolocation.io/ipgeo?apiKey=\".$apiKey.\"\u0026ip=\".$ip.\"\u0026lang=\".$lang.\"\u0026fields=\".$fields.\"\u0026excludes=\".$excludes;\n        $cURL = curl_init();\n\n        curl_setopt($cURL, CURLOPT_URL, $url);\n        curl_setopt($cURL, CURLOPT_HTTPGET, true);\n        curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);\n        curl_setopt($cURL, CURLOPT_HTTPHEADER, array(\n            'Content-Type: application/json',\n            'Accept: application/json'\n        ));\n        \n        return curl_exec($cURL);\n    }\n?\u003e\n```\n\n### Example\n\nHere is an example to get the geolocation for a list of IP addresses and display the result as a table:\n\n```php\n\u003cstyle\u003e\n    table, th, tr, td {\n        border: 1px solid black;\n        border-collapse: collapse;\n    }\n\n    th, td {\n        padding: 5px 30px;\n    }\n\u003c/style\u003e\n\n\u003c?php\n    $apiKey = \"PUT_YOUR_API_KEY_HERE\";\n    $ips = array(\"3.3.3.3\", \"4.4.4.4\", \"5.5.5.5\", \"6.6.6.6\", \"7.7.7.7\");\n\n    echo \"\u003ctable\u003e\";\n    echo \"\u003ctr\u003e\";\n    echo \"\u003cth\u003eIP\u003c/th\u003e\";\n    echo \"\u003cth\u003eContinent\u003c/th\u003e\";\n    echo \"\u003cth\u003eCountry\u003c/th\u003e\";\n    echo \"\u003cth\u003eOrganization\u003c/th\u003e\";\n    echo \"\u003cth\u003eISP\u003c/th\u003e\";\n    echo \"\u003cth\u003eLanguages\u003c/th\u003e\";\n    echo \"\u003cth\u003eIs EU Member?\u003c/th\u003e\";\n    echo \"\u003cth\u003eCurrency\u003c/th\u003e\";\n    echo \"\u003cth\u003eTimezone\u003c/th\u003e\";\n    echo \"\u003c/tr\u003e\";\n\n    foreach ($ips as $ip) {\n        $location = get_geolocation($apiKey, $ip);\n        $decodedLocation = json_decode($location, true);\n\n        echo \"\u003ctr\u003e\";\n\n        if ($decodedLocation['message'] != '') {\n            echo \"\u003ctd\u003e\".$ip.\"\u003c/td\u003e\";\n            echo \"\u003ctd\u003e\".$decodedLocation['message'].\"\u003c/td\u003e\";\n        } else {\n            echo \"\u003ctd\u003e\".$decodedLocation['ip'].\"\u003c/td\u003e\";\n            echo \"\u003ctd\u003e\".$decodedLocation['continent_name'].\" (\".$decodedLocation['continent_code'].\")\u003c/td\u003e\";\n            echo \"\u003ctd\u003e\".$decodedLocation['country_name'].\" (\".$decodedLocation['country_code2'].\")\u003c/td\u003e\";\n            echo \"\u003ctd\u003e\".$decodedLocation['organization'].\"\u003c/td\u003e\";\n            echo \"\u003ctd\u003e\".$decodedLocation['isp'].\"\u003c/td\u003e\";\n            echo \"\u003ctd\u003e\".$decodedLocation['languages'].\"\u003c/td\u003e\";\n\n            if ($decodedLocation['is_eu'] == true) {\n                echo \"\u003ctd\u003eYes\u003c/td\u003e\";\n            } else {\n                echo \"\u003ctd\u003eNo\u003c/td\u003e\";\n            }\n            \n            echo \"\u003ctd\u003e\".$decodedLocation['currency']['name'].\"\u003c/td\u003e\";\n            echo \"\u003ctd\u003e\".$decodedLocation['time_zone']['name'].\"\u003c/td\u003e\";\n        }\n\n        echo \"\u003c/tr\u003e\";\n    }\n\n    echo \"\u003c/table\u003e\";\n\n    function get_geolocation($apiKey, $ip, $lang = \"en\", $fields = \"*\", $excludes = \"\") {\n        $url = \"https://api.ipgeolocation.io/ipgeo?apiKey=\".$apiKey.\"\u0026ip=\".$ip.\"\u0026lang=\".$lang.\"\u0026fields=\".$fields.\"\u0026excludes=\".$excludes;\n        $cURL = curl_init();\n\n        curl_setopt($cURL, CURLOPT_URL, $url);\n        curl_setopt($cURL, CURLOPT_HTTPGET, true);\n        curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);\n        curl_setopt($cURL, CURLOPT_HTTPHEADER, array(\n            'Content-Type: application/json',\n            'Accept: application/json'\n        ));\n\n        return curl_exec($cURL);\n    }\n?\u003e\n```\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIPGeolocation%2Fip-geolocation-api-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIPGeolocation%2Fip-geolocation-api-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIPGeolocation%2Fip-geolocation-api-php/lists"}