content top
Block Country with GeoIP

Block Country with GeoIP

Alright, i think this topic has been discussed again and again but i still find some users having hard time time installing GeoIP in their hosts.

No problem guys, you are not alone. At first i installing GeoIP, i feeling so difficult too. but based on my experience from trying in many codes, you can try these codes in your website to block a country or many countries. Im promise with these codes you will be success to block a country even if you use a share host.

Okey i will give you step by step to use this GeoIP.

1. Download :  geoip.inc and geoip.dat(search a link Download the latest GeoLite Country Binary Format) from MaxMind

2. Create a new folder “GeoIP“  in your phproxy/website main folder contain geoip.inc and geoip.dat. (Remember geoip.dat not geoip.dat.rar)

3. Copy this code and paste in your index.php, Put this at the top of index.php

<?PHP
include('GeoIP/geoip.inc'); //this file must exist in your directory
 
$gi = geoip_open('GeoIP/GeoIP.dat',GEOIP_STANDARD);
 
// get the ip of the visitor
$addr = getenv('REMOTE_ADDR');
// translate his ip to a country code
$country = geoip_country_code_by_addr($gi, $addr);
// close the geo database
geoip_close($gi);
 
$badcountry = array('Example','Example','Example','Example');
// You can change the example with any countries that you want to block
 
// redirect them if they suck
if(in_array($country, $badcountry))
header('Location: http://www.whateva.com'); //enter a url or page on your site
?>

4. OPTIONAL-IF YOU GET ERROR LIKE THIS

Fatal error: Cannot redeclare geoip_country_code_by_name() in /home/blablabla/public_html/GeoIP/geoip.inc on line 347

OPEN your geoip.inc in your geoip directory and search line 347.
you will find these codes :

function geoip_country_code_by_name($gi, $name) {
  $country_id = geoip_country_id_by_name($gi,$name);
  if ($country_id !== false) {
        return $gi->GEOIP_COUNTRY_CODES[$country_id];
  }
  return false;
}
 
function geoip_country_name_by_name($gi, $name) {
  $country_id = geoip_country_id_by_name($gi,$name);
  if ($country_id !== false) {
        return $gi->GEOIP_COUNTRY_NAMES[$country_id];
  }
  return false;
}

replace with this codes :

/*
function geoip_country_code_by_name($gi, $name) {
  $country_id = geoip_country_id_by_name($gi,$name);
  if ($country_id !== false) {
        return $gi->GEOIP_COUNTRY_CODES[$country_id];
  }
  return false;
}
 
function geoip_country_name_by_name($gi, $name) {
  $country_id = geoip_country_id_by_name($gi,$name);
  if ($country_id !== false) {
        return $gi->GEOIP_COUNTRY_NAMES[$country_id];
  }
  return false;
}
*/

Have done…but remember !!! you may take step 4 if you getting error.
Enjoy with that codes…thanks

PS: This is not my original codes.
Source: http://www.netbuilders.org/ and xrvel.com

8 Comments »

  1. avatar comment-top

    nice info mate
    thanks for sharing

    :sip:

    comment-bottom
  2. avatar comment-top

    wonderfull tips, i will use your tips.

    What’s is some country that must be blocked ? Please share it with us

    Thanks

    comment-bottom
  3. avatar comment-top

    bedegongsia: nice info mate
    thanks for sharing:sip:

    Yeah thanks for read the post too..:koprol:

    jangkrikjr: wonderfull tips, i will use your tips.
    What’s is some country that must be blocked ? Please share it with usThanks

    hum…its depend with your needs..i will give an example :
    if you want to block China you can types CN. if you want block India you can types
    IN…(those just an example):tidur:

    comment-bottom
  4. avatar comment-top

    My next question :

    what country that need to block in web proxy business ?

    comment-bottom
  5. avatar comment-top

    Sip bro, I will try this.
    Nice Thanks

    comment-bottom
  6. avatar comment-top

    jangkrikjr: My next question :what country that need to block in web proxy business ?

    Ow..you want success in proxies business? Alright i have a friend, his name was Henry El maybe you can talk with him about proxy. He got much dollars from proxies. hehe:sikut:

    If you very interested in this business ill make some post related this post again.:hehe:

    comment-bottom
  7. avatar comment-top

    admin:
    Ow..you want success in proxies business? Alright i have a friend, his name was Henry El maybe you can talk with him about proxy. He got much dollars from proxies. heheIf you very interested in this business ill make some post related this post again.

    :ngakak: I will try to contact him….

    :hihi:

    comment-bottom
  8. avatar comment-top

    jangkrikjr:
    I will try to contact him….

    Hahahaha…alrite bro…ill contact him too about proxy..heheh lol:hehe:

    comment-bottom

RSS feed for comments on this post. TrackBack URL

Leave a comment

:hihi: :hiks: :melet: :nangis: :ngakak: :puyeng: :sip: more »