How to block a country?

Discussion in 'PHP' started by adamjblakey, Oct 15, 2007.

  1. #1
    Hi,

    I have a customer who wants to block anyone accessing his site from Czech Republic. How would i go about doing this?

    Cheers,
    Adam
     
    adamjblakey, Oct 15, 2007 IP
  2. jkrish41

    jkrish41 Banned

    Messages:
    2,416
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have to block the IP range.

    Google the IP range of Czech Republic, and ban.
     
    jkrish41, Oct 15, 2007 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Thank you for that, what would be the code to do that? and would it be using .htaccess?
     
    adamjblakey, Oct 15, 2007 IP
  4. jonimontana

    jonimontana Well-Known Member

    Messages:
    262
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #4
    $array = array("All of the ips...");
    
    foreach ($array as $ip)
    {
    if ($_SERVER['REMOTE_ADDR'] == $ip)
    {
    die("Error...");
    }
    
    Code (markup):
     
    jonimontana, Oct 15, 2007 IP
  5. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #5
    You can create a .htaccess with the following content:

    
    Order Allow,Deny
    Deny from 69.28
    Allow from all
    
    Code (markup):
    This will block any IP in the range of 69.28.*.*
     
    theOtherOne, Oct 15, 2007 IP
  6. grikis

    grikis Banned

    Messages:
    333
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    if(geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])=="cz"){
    echo "This country is banned!";
    die;
    }
    ?>
     
    grikis, Oct 15, 2007 IP