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!
|
Hi thanks. Is that available on free plan?
And beside on that I have another problem with cloudflare: Whenever I adjust dns to cloudflare my wordpress site starts logging out me from backend. Every 10 or 20 seconds it keeps logging me out and asks for login again and also the website posts goes back to older times. I tried everthing: like purging cache , deleting other caching files plugins but it didnt fix this issue.