View Single Post
Old 11-03-2017, 05:55 AM  
faperoni
Confirmed User
 
faperoni's Avatar
 
Industry Role:
Join Date: Feb 2015
Location: Amsterdam
Posts: 165
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!
__________________
Faperoni

Last edited by faperoni; 11-03-2017 at 06:00 AM.. Reason: typo
faperoni is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote