1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirect Visitors Based On Country?

Discussion in 'HTML & JavaScript' started by uscoobyk, Sep 9, 2010.

  1. uscoobyk

    uscoobyk Newbie

    Joined:
    Jun 16, 2010
    Messages:
    32
    Likes Received:
    3
    Occupation:
    SEO Pro
    Location:
    UK
    Hello all,

    Sorry if this has already been discussed, but I wasn't able to find it.

    I was wondering if anyone knows of a script which will allow visitors to be redirected based on country.

    Ex: USA - will visit the .com however, if a visitor comes from the UK - they'll be directed to the co.uk site. - Reason for this is USA customers will see $ and UK will see £.

    Thanks in advanced. :cool:
     
  2. wacked

    wacked Newbie

    Joined:
    Jul 17, 2010
    Messages:
    19
    Likes Received:
    2
    GeoIP.
    Upload all files in the package.
    PHP:
    $RedirectSites = array('US' => 'SITE1''UK' => 'SITE2''PL' => 'SITE3');
    $Country GetCountryCodeByIP($_SERVER['REMOTE_ADDR']);
    if(isset(
    $RedirectSites[$Country]))
    {
        
    header('Location: '$RedirectSites[$Country]);
        exit;
    }
    PHP:
    function GetCountryCodeByIP($IP)
    {
        include(
    "base/geoip/geoip.inc");
        
    $gi geoip_open("base/geoip/GeoIP.dat",GEOIP_STANDARD); 
        
    $country=geoip_country_code_by_addr($gi$IP);
        
    geoip_close($gi);
        return 
    $country;
    }
     
    • Thanks Thanks x 1
  3. millionairenextdoor

    millionairenextdoor Newbie

    Joined:
    May 19, 2009
    Messages:
    5
    Likes Received:
    1
    Occupation:
    IT
    Location:
    Istanbul
    thanks for the code. i got it working on my first try :)