This service will locate the geo-location of a specific ipv4 or ipv6 IP address. The service uses a combination of public databases, services and exceptions made on the basis of tests in order to get more accurate results.
* 99.99% accuracy in locating a country and a continent.
* 99.99% accuracy when locating an ISP.
* 90% accuracy when locating a city.
** The percentages are rounded off based on our personal testing.
Your detected location
You need to be logged in user before you can use the service.
We simplified the login / registration in the easiest way possible. Only you need to sign in with your Google / Gmail account to continue. After logging into the token field (below) you will be able to use your personal token on PHP.mk services.
Personal Token
Login to show token!
Version ({version}): v1.0
IP address ({ip}): ?ip= e.g. "3.235.11.178"
service end-point
HTTP/GET https://api.php.mk/ip2geo/{version}?token={token}&ip={ip}
Example HTTP/GET request
https://api.php.mk/ip2geo/v1.0?token=&ip=3.235.11.178
Example PHP
$url='https://api.php.mk/ip2geo/v1.0?token=&ip='.urlencode(isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']); $jsonResponse=file_get_contents($url); $response= json_decode($jsonResponse,true); echo '<pre>'; print_r($response['data']); exit();
Example cUrl
curl -X GET 'https://api.php.mk/ip2geo/v1.0?token=&ip=3.235.11.178';
Example Javascript
var xhr = new XMLHttpRequest(); xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { var response_data=JSON.parse(this.responseText).data; console.log(response_data); } }); xhr.open("GET", "https://api.php.mk/ip2geo/v1.0?token=&ip=3.235.11.178"); xhr.send();
Example jQuery / JavaScript
$.getJSON('https://api.php.mk/ip2geo/v1.0?token=&ip=3.235.11.178',function(r){ console.log(r.data); }).error(function(error){ console.log(error.responseJSON.msg); });
The answer is always in JSON format
The answer from the service is the data for the requested location in JSON format.
Example response
{ "error": false, "status_text": "OK", "status_code": 200, "data": { "ip": "95.180.xxx.xxx", "continent": { "code": "EU", "name": "Europe" }, "country": { "code": "MK", "code3": "MKD", "name": "Macedonia" }, "city": { "name": "Skopje", "postal_code": "1000", "latitude": "41.9973", "longitude": "21.4325" }, "isp": { "name": "Име на интернет провајдерот", "asn": "AS123456" } } }