.htaccess file and block country

Discussion in 'Programming' started by TheSyndicate, Mar 9, 2009.

  1. #1
    I want to block people from some country to register on my site but i want to them to be able to see the index file.

    I have a code for block them trough the .htaccess file on the index but how do i write the code for the register.php file?
     
    TheSyndicate, Mar 9, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    I dont know how you do it via .htaccess but I would do it with a query like this

    
    <?php
    error_reporting(0);
    $ip = $_SERVER['REMOTE_ADDR'];
    $file = file_get_contents("http://www.melissadata.com/lookups/iplocation.asp?ipaddress=" . $ip);
    preg_match('^<tr><td align="right">Country</td><td><b>([A-Z]+)</b></td></tr>^',$file , $country);
    $country = $country[1];
    
    
    
    if($country == "COUNRY NAME HERE IN UPPER CASE") {
            print "YOU ARE NOT ALLOWED ON THIS PAGE";
    	exit;
    }
    
    
    
    ?>
    
    
    PHP:
    Just paste on the head (begining) of pages you want to blocK
     
    crivion, Mar 9, 2009 IP
  3. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #3
    I need to put all the countries there? and i want to forward the blocked countries.
     
    TheSyndicate, Mar 9, 2009 IP
  4. richybear

    richybear Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    For this method is the only thing I would need to change be:

    if($country == "COUNRY NAME HERE IN UPPER CASE") { <<<< Put country here and if it's more then one would it look like this:

    if($country == "CANADA", "UNITED STATES", "CHINA") {


    print "YOU ARE NOT ALLOWED ON THIS PAGE"; <<<< I assume you put what you want here. And put quotes?

    Or is everthing in RED need to be changed?

    Thanks
     
    richybear, Mar 9, 2009 IP
  5. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #5
    i want to foward the blocked people...
     
    TheSyndicate, Mar 9, 2009 IP
  6. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #6
    nabil_kadimi, Mar 10, 2009 IP
  7. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #7
    Do i need to have my own server beucase i dont have it. I used shared
     
    TheSyndicate, Mar 10, 2009 IP
  8. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #8
    That's fine
     
    nabil_kadimi, Mar 10, 2009 IP
  9. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #9
    if you wanna forward just put
    print "<meta http-equiv=\"refresh\" content=\"0; url=yoururl\">";
     
    crivion, Mar 10, 2009 IP
  10. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #10
    yes i want to forward the countries that i blocked.
     
    TheSyndicate, Mar 10, 2009 IP
  11. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #11
    whats that hard dude?
    replace
    print "YOU ARE NOT ALLOWED ON THIS PAGE";
    with
    print "<meta http-equiv=\"refresh\" content=\"0; url=URL TO FORWARD TO\">";

    in the script I gave upper
     
    crivion, Mar 10, 2009 IP
  12. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #12
    buldozerceto, Mar 10, 2009 IP
  13. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #13
    right i said that no problem thanks :)
     
    TheSyndicate, Mar 10, 2009 IP
  14. king_elf

    king_elf Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    king_elf, Mar 10, 2009 IP
  15. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #15
    i have not tried it yet i will soon i just need to finish my other project but still looking for more samples if somebody have
     
    TheSyndicate, Mar 11, 2009 IP