1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Block A country , How ?

Discussion in 'PHP' started by ofir12, Aug 8, 2008.

  1. #1
    I want to block only 1 country from acsess to my server.


    How can i do it ?

    I am from this country and i need to have the option to acsess the server
    .


    Thanks in advance
     
    ofir12, Aug 8, 2008 IP
  2. love_natasha

    love_natasha Banned

    Messages:
    170
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    not sure why you want to do it ? care to share
     
    love_natasha, Aug 8, 2008 IP
  3. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #3
    nabil_kadimi, Aug 8, 2008 IP
  4. ofir12

    ofir12 Peon

    Messages:
    424
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I know this way of ip2nation , but I want to block 'X' country , I am Also from 'x' country , and i want to see the website, how can i do it ??
     
    ofir12, Aug 8, 2008 IP
  5. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #5
    Then use a HTTP/php authentification if user is from 'X' country
     
    nabil_kadimi, Aug 8, 2008 IP
  6. Trusted Writer

    Trusted Writer Banned

    Messages:
    1,370
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    160
    #6
    There is a PHP script inside www.sourceforge.net that redirects specific countries to any given page or URL outside your server.

    I don't remember the name but use "country redirection" as query to search and filter the results to programming language PHP

    It works, I had it installed on a website a couple of years back and doesn't require the huge country/IP database required by others.
     
    Trusted Writer, Aug 8, 2008 IP
  7. ofir12

    ofir12 Peon

    Messages:
    424
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7

    But i am also from X country...

    then it will block me also , thats my problem mate
     
    ofir12, Aug 8, 2008 IP
  8. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #8
    why would you want to block you country ????? if you live there
     
    jpinheiro, Aug 8, 2008 IP
  9. ofir12

    ofir12 Peon

    Messages:
    424
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It doesnt matter ,I need to do it.
     
    ofir12, Aug 8, 2008 IP
  10. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #10
    huh... I told you to use an authentification system, if the visitor is from your country, you redirect him to the authentification page, if you want to visit your website then you will provide the password...

    Anyway, do you have a good PHP knowledge?
    Is you ISP giving you a static IP ?
     
    nabil_kadimi, Aug 8, 2008 IP
  11. CarcaBot

    CarcaBot Active Member

    Messages:
    389
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #11
    or u can use a .htacces file an example is :
    
    <Limit GET HEAD POST>
    order deny,allow
    # Country: AFGHANISTAN
    # ISO Code: AF
    # Total Networks: 14
    # Total Subnets:  65,792
    allow from 58.147.128.0/19
    allow from 117.55.192.0/20
    allow from 117.104.224.0/21
    allow from 119.59.80.0/21
    allow from 121.58.160.0/21
    allow from 121.100.48.0/21
    allow from 121.127.32.0/19
    allow from 125.213.192.0/19
    allow from 202.56.176.0/20
    allow from 202.86.16.0/20
    allow from 203.174.27.0/24
    allow from 203.215.32.0/20
    allow from 210.80.0.0/19
    allow from 210.80.32.0/19
    #
    deny from all
    </Limit>
    
    Code (markup):
     
    CarcaBot, Aug 8, 2008 IP
  12. guzz

    guzz Guest

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    you can use, ip-to-country or maxmind products to block or redirect it.

    here is links:
    
    http://ip-to-country.webhosting.info/
    http://www.maxmind.com/app/geolitecountry
    [code]
    
    you may see usage of databases at their site.
    Code (markup):
     
    guzz, Aug 8, 2008 IP
  13. dylanj

    dylanj Peon

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #13
    Use the database from http://www.ip2nation.com/, and then use this:
    
    if ($countryName == "[Your Country Name]" && $_SERVER['REMOTE_ADDR'] != "[Your IP Address]")
    {
      header ("Location: http://www.yoursite.com/banned.php");
    }
    
    Code (markup):
     
    dylanj, Aug 8, 2008 IP
  14. ofir12

    ofir12 Peon

    Messages:
    424
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    It will ban the country except me ?
     
    ofir12, Aug 8, 2008 IP
  15. jliu

    jliu Peon

    Messages:
    235
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #15
    GeoIP/mod_geoip makes it very easy to block access to a one or multiple countries. You can configure it so that access by you is allowed.
     
    jliu, Aug 8, 2008 IP
  16. payu

    payu Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #16
    here is a code snippet using maxmind free geoip country lite version

    1. you need to download 2 files.
    http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
    http://www.maxmind.com/download/geoip/api/php/geoip.inc
    Code (markup):
    2. unzip GeoIP.dat.gz

    3. code

    
      require('geoip.inc');
    
      $banned_country = ''; // your country code (look inside geoip.inc for the country code).
    
      $ip = $_SERVER['REMOTE_ADDR'];
    
      $gi = geoip_open('GeoIP.dat', GEOIP_STANDARD);
      $ip_country = geoip_country_code_by_addr($gi, $ip);
      geoip_close($gi);
    
      if ($ip_country == $banned_country) {
        header('Location: http://google.com'); // redirect to where you want.
      }
    
    PHP:
     
    payu, Aug 8, 2008 IP
  17. dylanj

    dylanj Peon

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #17
    Yup, it sure will.
     
    dylanj, Aug 9, 2008 IP
  18. socketmail

    socketmail Guest

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #18
    To keep yourself safe just enter in a firewall your IP, or IP Range :)
     
    socketmail, Aug 9, 2008 IP
  19. ofir12

    ofir12 Peon

    Messages:
    424
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19

    But then my ip is blocked too...

    thats my problem
     
    ofir12, Aug 9, 2008 IP
  20. payu

    payu Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #20
    if you'd like to exclude your own ip from being banned, you can try using free service like no-ip.com or dyndns.com combining with their small windows program to automatically detect your current ip and update a hostname of your choice on their system.

    and here is the code to exclude your hostname.

    
    require('geoip.inc');
    
    $banned_country = ''; // your country code (look inside geoip.inc for the country code).
    $exclude_hostname = ''; // your hostname which you register with no-ip.com or dyndns.com
    
    $ip = $_SERVER['REMOTE_ADDR'];
    
    $gi = geoip_open('GeoIP.dat', GEOIP_STANDARD);
    $ip_country = geoip_country_code_by_addr($gi, $ip);
    geoip_close($gi);
    
    $exclude_ip = gethostbyname($exclude_hostname);
    
    if ($ip != $exclude_ip) {
      if ($ip_country == $banned_country) {
        header('Location: http://google.com'); // redirect to where you want.
      }
    }
    
    PHP:
     
    payu, Aug 9, 2008 IP