I am trying to restrict my site to a specific country using this code that I found and I can't seem to be able to get it to work.
My problem is that its always returning true even when $country
is different than what's in the array
I know restricting my site by GeoIP isn't fool proof but it will keep my issue down of people trying to signup from different countries as the events we host are limited to a small geographic area.
I have checked to see if my issue has to do with caching and my site isn't caching the output.
I also know that $country
is working as I've tried echo ($country);
Here is the code
$allowed_countries = array("CA", "US");
$country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
if (in_array($country, $allowed_countries)) {
header('Location: http://www.letsgetsocialclub.com/site');
} else {
echo "Sorry The Let's Get Social Club is not available in your country";
}