Skip to content

Instantly share code, notes, and snippets.

@lukasdoerr
Created August 17, 2021 12:48
Show Gist options
  • Save lukasdoerr/7a9acf31f8e37de1ed55d7c1124b8ef1 to your computer and use it in GitHub Desktop.
Save lukasdoerr/7a9acf31f8e37de1ed55d7c1124b8ef1 to your computer and use it in GitHub Desktop.
[PHP] ldoerr.com IP API Call
<?php
//Check if there is a query in GET
if(!$_GET['query']) {
//If not, we can just use our own ip address
$addr = $_SERVER['REMOTE_ADDR'];
}
else {
$addr = $_GET['query'];
}
//You can get your API Key at https://united-hosting.eu/?page=api
$apiKey = 'YOUR-API-CODE-HERE';
$apiUrl = 'https://united-hosting.eu/api/?api_key='.$apiKey.'&type=ip&addr='.$addr;
//You can also use curl, but it has to be enabled.
$jsondata = file_get_contents($apiUrl);
$ipInfo = json_decode($jsondata, true);
//If you want to look, what your API Answer looks like uncomment this:
/*
echo "<pre>";
print_r($ipInfo);
echo "</pre><br><br>";
*/
// Simple check if API Call worked or not.
if($ipInfo['Api']['ApiCall'] <> 'Success') {
echo "ERROR in API Call!";
}
else {
echo "API Call Successfull!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment