I am almost banging my head....
I searched a lot here and in google... but I am not sure I am doing things right.
here is my code:
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
$country= file_get_contents("http://ipinfo.io/$ip/json");
echo ($ip.'---'.$country);
The problem is when I run this code (Not on localhost, but on my server)... I see some ip like 10.100.x.x.
and country I get is empty.
but when I visit http://ipinfo.io/, I see some different IP for me. It is something like 182.183.x.x and I can see my country and city information correctly.
I tried some other IP locators as well and All say my IP address is 182.183.x.x. I tried to locate 10.100.x.x. as well.. All services returned with empty country.
So how can I obtain my real IP in php?? What am I doing wrong?