Created
August 17, 2021 12:48
-
-
Save lukasdoerr/7a9acf31f8e37de1ed55d7c1124b8ef1 to your computer and use it in GitHub Desktop.
[PHP] ldoerr.com IP API Call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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