I have IP ranges of the country. And I am checking the the user IP address within this ranges if true then he is able to see the site otherwise he wont. I have use following code,
$ip = $_SERVER['REMOTE_ADDR'];
if(ip2long($ip) >= $ipstart && ip2long($ip) <= $ipend){
return true;
}
My question is that if somebody comes from different country suppose ABC with his laptop/notebook to another country suppose XYZ then will above code works? on the same laptop.
How will it be possible for the above scenario for ipv4 and ipv6?
[EDIT]
Which IP address $_SERVER['REMOTE_ADDR']
fetch, will it be the machine IP or the connection IP, so that we can know that he now in this country?
Thanks
$result = json_decode(file_get_contents('https://www.iplocate.io/api/lookup/8.8.8.8')); echo $result->country;
- Disclaimer: I run this service. – ttarik