How to filter US traffic on site?

Discussion in 'Programming' started by globalnetworksuccess, Aug 16, 2008.

  1. #1
    I would like to approve only traffic from US and other traffic redirect to other site, how can I do it?
     
    globalnetworksuccess, Aug 16, 2008 IP
  2. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You'll need an IP to Country database, I'm not sure if there is a free one or not. . . But you get that, and query the ip, then mod the header if they aren't from the US.

    If you google 'IP to Country database' you will be able to find one.

    =]
     
    ToddMicheau, Aug 16, 2008 IP
  3. globalnetworksuccess

    globalnetworksuccess Peon

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Do you know any script to do it?
     
    globalnetworksuccess, Aug 16, 2008 IP
  4. iRakic

    iRakic Member

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    You can do it by "Geo IP"...
    Max Mind, have a free database for that, with API support for all popular languages.

    If you need help we are here to help you, just post you code what you have done so far, and we will try to help you.
     
    iRakic, Aug 16, 2008 IP
  5. globalnetworksuccess

    globalnetworksuccess Peon

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    My server dotn allow to install maxmind software, i would have to upgrade to dedicate server..

    Any alternatives?
     
    globalnetworksuccess, Aug 16, 2008 IP
  6. DansTuts

    DansTuts Guest

    Messages:
    923
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok being I'm new here I thought I might try and be helpful so I've just coded you something that should do it without any MySQL database. It uses files provided by ip2country.

    You can download it from: danstuts.com/code/ip2location.zip
    Demo: danstuts.com/samples/ip2loc/location.php

    The demo will send you to Google if your from America, and if not it will send you to my homepage. Just upload the files then change the URLs in the location.php file.

    <?php
    $the_users_ip = $_SERVER['REMOTE_ADDR']; 
    $two_letter_country_code=iptocountry($the_users_ip);
    
    if ($two_letter_country_code=="US") { 
       // The user is from the states,  thus send them to one page
       header('Location:GOOGLE I CANT TYPE URLS YET');[
       // Else the user is from outside US
    } else { 
       header('Location:MY WEBSITE');
    }
    
    function iptocountry($ip) {   
        $numbers = preg_split( "/\./", $ip);   
        include("ip_files/".$numbers[0].".php");
        $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);   
        foreach($ranges as $key => $value){
            if($key<=$code){
                if($ranges[$key][0]>=$code){$country=$ranges[$key][1];break;}
                }
        }
        if ($country==""){$country="unkown";}
        return $country;
    }
    ?>
    PHP:
     
    DansTuts, Aug 16, 2008 IP
  7. globalnetworksuccess

    globalnetworksuccess Peon

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    How accurate is it?
     
    globalnetworksuccess, Aug 16, 2008 IP
  8. DansTuts

    DansTuts Guest

    Messages:
    923
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'd say 95-97%. It's the same method Hulu uses, so it should work fine.
     
    DansTuts, Aug 16, 2008 IP
  9. Dave Parish

    Dave Parish Peon

    Messages:
    99
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    do you think it would be possible to do this on the registrar level, or a little off topic, is it possible to build in an option to load balance from the registrar or if you are the registrar to add DNS load balancing as an option.
     
    Dave Parish, Aug 16, 2008 IP
  10. iRakic

    iRakic Member

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #10
    There is no need for installing it, like you are installing some binary application, you only need to copy it thru FTP, and use API for reading Geo IP database.
    Here are direct links to files Geo IP Country - binary Geo IP City - binary. Then go to Max Mind website, and get API for you language.
    There is also a CSV version, that I have used by converting it into DB (MySQL)...

    They have very accurate database, but if you want more accurate there is a paid version.
     
    iRakic, Aug 17, 2008 IP
  11. blueribbon

    blueribbon Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I have personally used country2ip and it works great, my advice would be to parse the ip2c files into a mysql database and have a script run weekly to update your ip2c database, then its easy to run mysql queries to find out which country your visitor is from and redirect accordingly.
     
    blueribbon, Aug 18, 2008 IP
  12. superstan

    superstan Peon

    Messages:
    244
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    i m using one IP2Country on my site in my admin panel to see my users origin. that works awesom
     
    superstan, Aug 18, 2008 IP
  13. red-sky

    red-sky Peon

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Sorry if this is a really noobish question, i can't seem to get my head around this GeoIp etc. Am I required to rewrite my webpages in php to use this?
     
    red-sky, Sep 1, 2008 IP