Quote:
Originally Posted by faperoni
No need for ip2location if you are using Cloudflare. Just enable the "IP Geolocation" option and you can get the visitors country like this:
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
Now lets say you want to block visitors from Kuwait you simply do:
if($country_code == 'KW'){
exit; //or redirect or whatever
}
Multiple countries:
$blocked_countries = array('KW','AE','IQ');
if (in_array($country_code, $blocked_countries)) {
exit;//or redirect whatever
}
CF guide:
support.cloudflare[.]com/hc/en-us/articles/200168236-What-does-Cloudflare-IP-Geolocation-do-
Country codes:
github[.]com/lukes/ISO-3166-Countries-with-Regional-Codes/blob/master/all/all.csv
Let me know if you need help setting this up, good luck!
|
Where should I add this code:
Code:
if($country_code == 'KW'){
exit; //or redirect or whatever
}
to .htaccess or where?
Does it works on shared hosting?