For some reason this code only works when I change the $ip
to my current IP address. Is there something that I need to do to the PHP.ini file for this code to work dynamically?
Even when I download the code from the internet it does not display, and it has nothing to do with the API I am using, I even tried PHP $_SERVER['REMOTE_ADDR'] empty that code wont work.i think there is a setting i need to do. i am using MAMP, and a MAC. this is what its displaying "::1"
<?php
// Get User IP
if(! empty($_SERVER['REMOTE_ADDR']) ){
$ip = $_SERVER['REMOTE_ADDR'];
}
else{
$ip = empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? '' : $_SERVER['HTTP_X_FORWARDED_FOR'];
}
//Send the API request with user Ip
$ipinfoAPI = "http://ipinfo.io/{$ip}/json";
//get the APi requeted data
$load = file_get_contents($ipinfoAPI);
//Convert it to the readable format
$return = json_decode($load);
echo $return->ip;
?>