Blacklist Countries

If you advertise your exchange specialises in traffic from specific locations then you may need a way to block folk trying to surf from outside that area.  There are many ways to do that, the following method is reliable and best of all it's free!  You may need to make adjustments depending on the control panel you use.

1. Download the database from Maxmind and place GeoIP.dat in your public_html folder. Make sure you spell it correctly and it IS case sensitive, it won't work if you change it.

2. Login to cPanel and select "PHP PEAR Packages", then in the "Install a PHP Extensions and Applications Package" text box type Net_GeoIP (Spelling and case ARE important). Click the button to install and you will see some result text. Don't worry if you see some errors that's normal but it must end up by saying "Succesfully installed". If it doesn't or you have not got the PEAR package facility you either need to speak to your host or work your way through what must be the most boring site on the web at http://pear.php.net/manual/en/package.netw...g.net-geoip.php

3. Add the following code to your signup template:-

<php>
/****************************************************************************
 * Selective country ban for Ventrino Traffic Exchange Scripts
 * Copyright Ventrino Software LLC and Maxmind. This product includes 
 * GeoLite data created by MaxMind, available from http://www.maxmind.com/
 * For usage see the Ventrino Traffic Exchange Script Owners Manual.
 * **************************************************************************/    

/// Path to the PEAR libraries, If you use control panel the path is
/// usually /home/XXXXX/php/Net/GeoIP.php where XXXXX is your username.  If
/// your host does not use cPanel then you will have to contact them for 
/// details or download and install them yourself from 
/// http://pear.php.net/package/Net_GeoIP/download
$path_to_net_geo_lib = "/home/XXXXX/php/Net/GeoIP.php";
require_once($path_to_net_geo_lib);

/// The redirect page can be the location you want to send countries you
/// have banned from accessing your site.  This could be another website or 
/// link on your page.  If you own two exchanges, one dealing with USA & 
/// Europe and the other with Asia you could redirect them as required. 
$redirect_page       =  "/nosignup.html";

/// Place the GeoIP.dat in the root directory of your website, this is usally
/// public_html, htdocs or wwwroot.  If you are unsure check with your host.
/// If your server is Linux make sure the filename is capitalised as shown
/// below.  As this is how it comes from Maxmin it's a good idea to leave it
/// as is.
$file = dirname(__FILE__)."/GeoIP.dat";

/// The following instantiates the class and uses the surfers IP address
/// to find the two letter country code.  No changes required here.
$geoip = Net_GeoIP::getInstance($file);
try {
    $country = strtolower($geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']));
} catch (Exception $e) {
    $country = '';
}
/// ~~~~~~~~~~~~~~~~~~~ List countries to ban here ~~~~~~~~~~~~~~~~~~~ 
/// Use the following lines to ban or redirect countries you do not 
/// want to access your exchange. For each country you must add a line
/// that starts with case and ends in a colon.  For example, to ban 
/// China add:-
///    case 'cn':
/// Note that the ctwo letter country code must be lowercase and 
/// surrounded with single quotes.  Here are a couple more examples:-
///    case 'af':
///    case 'eg':
/// These ban/redirect Afghanistan and Egypt respectively.
switch($country) {
  case 'cn':
  case 'af':
  case 'eg':
/// ~~~~~~~ Add countries to ban/redirect above this line ~~~~~~~
    header("Location: $redirect_page");
}
</php>

4. You must make three changes to the above code:-

Home Forum Client Area