Created
January 19, 2024 09:48
-
-
Save parsibox/c3ae6ac4655971788453bcde81cd5ea9 to your computer and use it in GitHub Desktop.
server ip with api
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 | |
// Make a request to ipify API | |
$apiUrl = 'https://api.ipify.org?format=json'; | |
$response = file_get_contents($apiUrl); | |
// Check if the request was successful | |
if ($response !== false) { | |
// Decode the JSON response | |
$data = json_decode($response, true); | |
// Extract and display the external IP address | |
if (isset($data['ip'])) { | |
$externalIP = $data['ip']; | |
echo "External IP Address: $externalIP"; | |
} else { | |
echo "Unable to retrieve IP address from the API."; | |
} | |
} else { | |
echo "Failed to connect to the API."; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment