Post
by Averyking » Tue Mar 24, 2015 3:52 pm
This solution may be help you
1.Download the latest Geo data and the class file
2.Copy the class file and the GeoIP data file into the same directory where the page is located (most of the time the root directory)
3.Include the class file inside your page and add the following code to request the country using the following code (below the include statements):
$gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
4.Define some country codes the "whitelist":
$my_countries = array('us', 'ca', 'gb', 'fr', 'de', 'nl');
5.Next place the following code below the $mycountries array:
if (!in_array(strtolower($country), $my_countries)) {
header('Location: some URL...');
exit;
}